Showing posts with label calculator using java. Show all posts
Showing posts with label calculator using java. Show all posts

Monday, October 5, 2015

Java Program to calculating value using Scanner in Java

Using this Program we can calculate given value of a&b using scanner. This program will help to build the calculator. So read carefully and implement this program.


package com.indra;

import java.util.Scanner;

public class SystemUsingScanner {
static int a;
static int b;
static int c;

public static void main(String[] hh) {
Scanner obj = new Scanner(System.in);
for (int i = 0; i >= 0; i++) {
System.out.println("1 Addition");
System.out.println("2 Substraction");
System.out.println("3 Multiplication");
System.out.println("4 Division");
System.out.println("5 for close your calculator");
int op = obj.nextInt();
boolean close = false;///// use to check case 5 for close this program
switch (op) {

case 1:
System.out.println("Enter the value of a & b for Addition");
a = obj.nextInt();
b = obj.nextInt();
c = a + b;
System.out.println(c);
break;
case 2:
System.out.println("Enter the value of a&b for multiplication");
a = obj.nextInt();
b = obj.nextInt();
c = a - b;
System.out.println(c);
break;
case 3:
System.out.println("Enter the value of a&b for multiplication");
a = obj.nextInt();
b = obj.nextInt();
c = a * b;
System.out.println(c);
break;
case 4:
System.out.println("Enter the value of a&b for multiplication");
a = obj.nextInt();
b = obj.nextInt();
c = a / b;
System.out.println(c);
break;
case 5:
close = true;
break;
default:
break;
}
if (close) {        /// condition true then program will close
break;
}
}
}
}

Tricks and Tips