If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.
People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360.
Sample Program Output
Program Listing
import java.util.Scanner;
public class calc {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char operator,reply;
do {
System.out.print("\n");
System.out.println("==============================================");
System.out.println("|| <<< SIMPLE CALCULATOR >>> ||");
System.out.println("==============================================");
System.out.print("\n");
System.out.print("ENTER AN EXPRESSION (ex. 2 + 2) :=> ");
double val1 = in.nextDouble();
operator=in.next().charAt(0);
double val2 =in.nextDouble();
switch (operator) {
case '+':
System.out.println("\n");
System.out.println("The sum is :=> " + (val1 + val2));
break;
case '-':
System.out.println("\n");
System.out.println("The difference is :=> " + (val1 - val2));
break;
case '/':
System.out.println("\n");
System.out.println("The quotient is :=> " + (val1 / val2));
break;
case '*':
System.out.println("\n");
System.out.println("The product is :=> " + (val1 * val2));
break;
default:
System.out.println("\n");
System.out.println("Please Try Again Sorry Wrong Operator...");
}
System.out.println("\n");
System.out.print("Do you Want To Continue (Y/N) :=> ");
reply=in.next().charAt(0);
} while(reply=='Y'|| reply=='y');
System.out.println("\n");
System.out.println("\t ===== END OF PROGRAM ======");
System.out.println("\n");
}
}
No comments:
Post a Comment