0

So far my code is like this in Java. I tried it in C and I used a FFLUSH() function to do this. Is there any such function in Java that can do this?

/**
 * 
 */
package UserInput;

import java.util.Scanner;

/**
 * @author ypava
 *
 */
public class UserInput {

    private static Scanner s,p5,q5,p4,q4,p3,q3,p2,q2,p,q,ch;
     //static float a,b,c;

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub


        //float a,b,c;

        int choice;

        String Rch;
        do{
        System.out.println("\t\t\t Menu");
        System.out.println("\t 1.Addition");
        System.out.println("\t 2.Subtraction");
        System.out.println("\t 3.Multiplication");
        System.out.println("\t 4.Division");
        System.out.println("\t 5.Modulus");
        System.out.println("");
        System.out.println("Please Enter Your Choice");
        s = new Scanner(System.in);
        choice=s.nextInt();


        switch(choice)
        {
        case 1:
        {
            System.out.println("Enter the Values of a & b");
            p5 = new Scanner(System.in);
            float a=p5.nextFloat();
            q5 = new Scanner(System.in);
            float b= q5.nextFloat();
            float c=a+b;
            System.out.println("The Sum is: \t" +c);
            break;

        }
        case 2:
        {
            System.out.println("Enter the Values of a & b");
            p4 = new Scanner(System.in);
            float a=p4.nextFloat();
            q4 = new Scanner(System.in);
            float b= q4.nextFloat();
            float c=a-b;
            System.out.println("The Difference is: \t" +c);
            break;
        }
        case 3:
        {
            System.out.println("Enter the Values of a & b");
            p3 = new Scanner(System.in);
            float a=p3.nextFloat();
            q3 = new Scanner(System.in);
            float b= q3.nextFloat();
            float c=a*b;
            System.out.println("The Multiplication is: \t" +c);
            break;
        }
        case 4:
        {
            System.out.println("Enter the Values of a & b");
            p2 = new Scanner(System.in);
            float a=p2.nextFloat();
            q2 = new Scanner(System.in);
            float b= q2.nextFloat();
            float c=a/b;
            System.out.println("The Division is: \t" +c);
            break;
        }
        case 5:
        {
            System.out.println("Enter the Values of a & b");
            p = new Scanner(System.in);
            float a=p.nextFloat();
            q = new Scanner(System.in);
            float b= q.nextFloat();
            float c=a%b;
            System.out.println("The Modulus is: \t" +c);
            break;
        }

       default:
           System.out.println("Wrong Option Entered");
           break;

        }

        System.out.println("Do you Want to Perform any other operation Y/N");
        ch = new Scanner(System.in);
         Rch=ch.nextLine();


        }while(Rch=="Y"|| Rch=="y");


    }

}
halfer
  • 19,824
  • 17
  • 99
  • 186

0 Answers0