Search

Thursday, November 24, 2011

Creating a Calculator Program With Java

import java.io. *;
cal class
{
public static void main (String args [])
{
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
String numbers = "";
int number;
double the amount;
SUM= 0;
String operator = "+";
char operator ='+';
System.out.println ("\ n");
do
{
try
{
System.out.println ("");
number = input.readLine ();
number = Integer.parseInt (number);
if (operator == '+')
{

SUM= SUM + number;
}
else if (operator == '-')
{
  SUM= SUM - the figure;
}
else if (operator == '*')
{
  SUM= SUM * numbers;
}
else if (operator == '/')
{
SUM= SUM / numbers;
}
else
{
System.out.println ("Operator Error ...");
}
}
catch (Exception e)
{
System.out.println ("Sorry wrong input please try again ....");
}

try
{
System.out.println ("");
input.readLine operator = ();
}
catch (Exception e)
{
System.out.println ("Sorry Operators wrong, please repeat ....");
}
operator.charAt operator = (0);
} while (operator! ='=');

System.out.println ("- \ n" + SUM + "\ n");
}
}

1 comments:

bisa dicoba nih..

salam blogwalking

hmsf08.blogspot.com

Post a Comment

 

Home | Blogging Tips And Trick | Simple Blogspot HTML | All About Informations | Interesting Site | Simple And Accurate Site

Copyright © 2010-2012 Interesting info Template Design by Fajar Hudy Pratama