Skip to content

A simple java calculator based on switch-case

by on February 4, 2011

//A simple java calculator based on switch case

public class Cal

{

public static void main(String args[])throws Exception

{

int a,b,c=0;

BufferedReader br=new BufferedReader(new InputStreanreader(System.in));

System.out.println(“Enter 1st number”);

a=Integer.parseInt(br.readLine());

b=Integer.parseInt(br.readLine());

System.out.println(“\nMENU\n1.Add\n2.Subtract\n3.Multiply\n4.Devide\nEnter your choice:”);

int ch=Integer.parseInt(br.readLine());

switch(ch)

{

case 1: c=a+b;

break;

case 2:c=a-b;

break;

case 3:c=a*b;

break;

case 4:c=a/b;

break;

default: System.out.println(“Wrong Choice”);

}

System.out.println(c);

}

}

 

About these ads

From → Codes, Java codes

Leave a Comment

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: