Skip to the content.

Lesson 1.3 - Rohan Bojja

System.out.printf("Player: %s\nScore: %d\tAccuracy: %.2f%%\nNote: \"%s\"\n", "Rohan", 2560, 92.73, "Great job!");

Player: Rohan
Score: 2560	Accuracy: 92.73%
Note: "Great job!"





java.io.PrintStream@71902c88
// This program uses formatting tools like %s, %d, %.2f, \n, \t, and \" to organize output clearly.
// They help align text, control decimal places, and include special characters like quotes or new lines.
// Using printf() makes the output cleaner, more readable, and more professional than plain print statements.

System.out.print("AP ");
System.out.println("CSA");
System.out.println("Rocks!");

AP CSA
Rocks!
System.out.println("C:\\Users\\Student");

C:\Users\Student
public class Menu {
    public static void main(String[] args) {
        int optionCount = 4;

        System.out.println("==== Main Menu ====");
        System.out.println("1. Start Game");
        System.out.println("2. View Scores");
        System.out.println("3. Exit");
        System.out.println("4. Settings");

        System.out.println("\nTotal options: " + optionCount);
    }
}

System.out.printf("Pi = %.2f\n", Math.PI);

Pi = 3.14





java.io.PrintStream@71902c88
import java.util.Scanner;

public class CalculatorMenu {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("==== Calculator Menu ====");
        System.out.println("1. Add");
        System.out.println("2. Subtract");
        System.out.println("3. Multiply");
        System.out.println("4. Divide");

        System.out.print("Choose an option (1-4): ");
        int choice = input.nextInt();

        System.out.print("Enter first number: ");
        double num1 = input.nextDouble();

        System.out.print("Enter second number: ");
        double num2 = input.nextDouble();

        double result = 0;

        if (choice == 1) {
            result = num1 + num2;
            System.out.println("Result: " + result);
        } else if (choice == 2) {
            result = num1 - num2;
            System.out.println("Result: " + result);
        } else if (choice == 3) {
            result = num1 * num2;
            System.out.println("Result: " + result);
        } else if (choice == 4) {
            if (num2 != 0)
                result = num1 / num2;
            else
                System.out.println("Error: Cannot divide by zero!");
            System.out.println("Result: " + result);
        } else {
            System.out.println("Invalid option!");
        }

        input.close();
    }
}