JAVA Lab Programs
1. Calculator using switch case: import java.util.Scanner; public class Calculator{ public static void main (String[] args) { Scanner scanner = new Scanner(System. in ); System. out .println( "Calculator" ); System. out .println( "1. Addition" ); System. out .println( "2. Subtraction" ); System. out .println( "3. Multiplication" ); System. out .println( "4. Division" ); System. out .println( "5. Exit" ); System. out .println( "Enter your choice: " ); int choice = scanner.nextInt(); switch (choice){ case 1 : System. out .println( "Enter two numbers: " ); int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); int sum = num1 + num2; System. out .println( "The sum is: " + sum); break ; case 2 : ...
Comments
Post a Comment