arithmetic operators in java

Question :
Write a java program that demonstrates the use of arithmetic operators.

Answer :
In this program we perform basic calculator functions like addition, subtraction, division and multiplication, which clearly shows the using of arithmetic operators in java.

1:  import java.io.BufferedReader;  
2: import java.io.IOException;
3: import java.io.InputStreamReader;
4: public class CalculatorDemo {
5: public static void main(String args[]) throws IOException
6: {
7: int a,b,c;
8: float s;
9: BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10: System.out.println("Enter first number");
11: a = Integer.parseInt(br.readLine());
12: b = Integer.parseInt(br.readLine());
13: c = a + b;
14: System.out.println("Sum :"+c);
15: c = a - b;
16: System.out.println("Difference :"+c);
17: c = a * b;
18: System.out.println("Product :"+c);
19: s = (float)a/b;
20: System.out.println("Quotient :"+s);
21: }
22: }



Ads by Google