JAVA PROGRAM FOR MATHEMATICAL OPERATIONS

A Simple Java Program for demonstrating mathematical operations:

importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
public class Rise {
public Rise(){};

public static void main (String[] args)
    {
System.out.println(“Hello”);
      String username = null;
      String userExit= “N”;

try {
while(userExit.equalsIgnoreCase(“N”))
                  {

BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
System.out.print(“Please enter user name : “);
username = reader.readLine();

System.out.println(“Welcome :” + username);
System.out.print(“Please enter A for Addition, S for Subtraction and M for Multiplication: “);

                  String userChoice = null;
userChoice = reader.readLine();

if(userChoice.equalsIgnoreCase(“A”))
                 {
System.out.print(“Please enter two numbers to add: “);
int a =  Integer.parseInt(reader.readLine());
int b =  Integer.parseInt(reader.readLine());
int c = a+b;
System.out.print(“The Sum is: “+c);
                 }

else if(userChoice.equalsIgnoreCase(“S”))
                 {
System.out.print(“Please enter two numbers to subtract: “);
int a = Integer.parseInt(reader.readLine());
int b = Integer.parseInt(reader.readLine());
int c = a-b;
System.out.print(“The Difference is: “+c);
                  }

else if(userChoice.equalsIgnoreCase(“M”))
                  {
System.out.print(“Please enter two numbers to multiply: “);
int a = Integer.parseInt(reader.readLine());
int b = Integer.parseInt(reader.readLine());
int c = a*b;
System.out.print(“The Product is : “+c);
                   }
else
                   {
System.out.print(“Error!!! “);
                   }
System.out.print(“Do you want to continue Y/N?: “);
                    String yesNo = reader.readLine();

if (yesNo.equalsIgnoreCase(“N”))
                    {
userExit =”Y”;
                    } 
else
                    {
userExit =”N”;
                    }
                  }

               } catch (IOException e) {
e.printStackTrace();
               }
         }
 }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s