Share all news to all guy ;)

Saturday, December 20, 2014


       This Java code is to sum two number , not for sum only and user can use it for Calculator of Two Number ;) . Because it have all operator ..............

public static void main(String[] args) {
        double Num1,Num2,Result=0;
        char op;
       
        Scanner In = new Scanner (System.in);
       
        System.out.print("Enter First Number: ");
        Num1 = In.nextDouble();
       
        System.out.print("Please Choose: ");
        System.out.print("'+','-','*','/','%' : ");
        op = In.next().charAt(0);
       
        System.out.print("Enter Second Number: ");
        Num2 = In.nextDouble();
       
         switch (op) {
            case '+': Result = Num1 + Num2; break;
            case '-': Result = Num1 - Num2; break;
            case '*': Result = Num1 * Num2; break;
            case '/': Result = Num1 / Num2; break;
            default : System.out.printf("Enter Wrong");
        }
        System.out.println("Result: " + Result);
    }
   
}

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.