Tuesday, 10 October 2017

using loop java calculator


mport java.util.*;
 public class loopCalculator
{
  public static void main(String args[])
{
      Scanner p = new Scanner(System.in);
      double num1,num2,res=0;
          int n;
 for(int i=1;i!=-1;i++)
{
   
  System.out.println("\nEnter 1 to calculate sum 2 for subtraction 3 for product 4 for division");
         n=p.nextInt();
      switch(n)
{
       case 1:
         System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
           res=num1+num2;
         System.out.printf("The sum of two numbers is :%f",res);
       break;
      case 2:
                 System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
           res=num1-num2;
         System.out.printf("The subtraction of two numbers is :%f",res);
       break;
            case 3:
                      System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
           res=num1*num2;
         System.out.printf("The product of two numbers is :%f",res);
       break;
case 4:
                     System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
            res=num1/num2;
         System.out.printf("The division of two numbers is :%d",res);
       break;
 default:
    System.out.println("You Enter a wrong number");
}}}}
      

0 comments:

Post a Comment