Welcome To Sudhara Dananjaya Blog!!!!!!!!!!!!!!!!!
Sunday, March 9, 2014
Calculator
import java.util.Scanner;
public class SimpleCalculator {
public static void main (String[] args)
{
int a,b,result=0;
char c;
Scanner input = new Scanner(System.in);
//Take inputs
System.out.println("Enter no. :");
a = input.nextInt();
System.out.println("Enter no. :");
b = input.nextInt();
System.out.println("Enter Operator :");
String st = input.next();
c = st.charAt(0);
//add a switch statement
switch(c)
{
case '+':
result = a+b;
System.out.println("Result = "+result);
break;
case '-':
result = a-b;
System.out.println("Result = "+result);
break;
case 'x':
result = a*b;
System.out.println("Result = "+result);
break;
case '/':
result = a/b;
System.out.println("Result = "+result);
break;
default:
System.out.println("Error");
}
}
}
public class SimpleCalculator {
public static void main (String[] args)
{
int a,b,result=0;
char c;
Scanner input = new Scanner(System.in);
//Take inputs
System.out.println("Enter no. :");
a = input.nextInt();
System.out.println("Enter no. :");
b = input.nextInt();
System.out.println("Enter Operator :");
String st = input.next();
c = st.charAt(0);
//add a switch statement
switch(c)
{
case '+':
result = a+b;
System.out.println("Result = "+result);
break;
case '-':
result = a-b;
System.out.println("Result = "+result);
break;
case 'x':
result = a*b;
System.out.println("Result = "+result);
break;
case '/':
result = a/b;
System.out.println("Result = "+result);
break;
default:
System.out.println("Error");
}
}
}
Monday, February 17, 2014
Monday, January 27, 2014
Saturday, March 20, 2010
Subscribe to:
Comments (Atom)


