Sie sind auf Seite 1von 3

Reverse Number import java.util.Scanner; public class Reverse { public static void main(String args[]) { int n, reverse = 0; System.out.

println("Enter the number to reverse"); Scanner in = new Scanner(System.in); n = in.nextInt(); while( n != 0 ) { reverse = reverse * 10; reverse = reverse + n%10; n = n/10; } System.out.println("Reverse of entered number is "+reverse); } } All arithmatic operations using switch import java.io.*; public class Arith{ public static void main(String[] args) throws Exception{ int x, y; BufferedReader object = new BufferedReader (new InputStreamReader(System.in)); System.out.println("Enter two numbers for operation:"); try{ x = Integer.parseInt(object.readLine()); y = Integer.parseInt(object.readLine()); System.out.println("1. Add"); System.out.println("2. Subtract"); System.out.println("3. Multiply"); System.out.println("4. Divide"); System.out.println("enter your choice:"); int a= Integer.parseInt(object.readLine()); switch (a){ case 1: System.out.println("The Addition is=" + (x+y)); break; case 2: System.out.println("The Subtraction is=" + (x-y)); break; case 3: System.out.println("The Multiplication is="+ (x*y)); break; case 4: System.out.println("The Division is="+ (x/y)); break; default: System.out.println("Invalid Entry!"); } } catch(NumberFormatException ne){ System.out.println(ne.getMessage() + " is not a numeric value.");

System.exit(0); } } } All arithmatic operations using switch import java.util.Scanner; class Arith1 { public static void main(String args[]) { int x , y ; char choice; System.out.println("Enter the first value"); Scanner in = new Scanner(System.in); x= in.nextInt(); System.out.println("Enter the second value"); Scanner sc = new Scanner(System.in); y = sc.nextInt();

System.out.println("\t\tMenu\n"); System.out.println("\t1. Addition System.out.println("\t2. Subtraction System.out.println("\t3. Division System.out.println("\t4. Multiplication try {

-----

Enter Enter Enter Enter

A S D M

\n"); \n"); \n"); \n");

System.out.println("Enter your choice :"); choice= (char)System.in.read(); switch (choice) { case 'A' : System.out.println("Addition of "+x+" and "+y+" : "+(x+y)); break ; case 'S' : System.out.println("Subtraction of "+x+" and "+y+" : "+(x-y) ); break ; case 'D' : System.out.println("Division of "+x+" and "+y+" : "+((float) x/(float)y)); break ; case 'M' : System.out.println("Multiplication of "+x+" and "+y+" : "+(x *y)); break ; default :System.out.println("Wrong choice !!"); } } catch(Exception e) { System.out.println("I/O Error"); } } }

Das könnte Ihnen auch gefallen