Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class main {
- public static Scanner scan = new Scanner(System.in);
- public static void main(String[] args) {
- // flag for infinite loop
- boolean flag = true;
- while (flag == true) {
- System.out.println(
- "Welcome to MATHEMATICA!!\nChoose the following options:\n(1):Find the value of a number squared\n(2):Find the value of a number cubed\n(3):Find the value of a number at any power\n(4):Exit");
- int choice = scan.nextInt();
- int value;
- System.out.println("You have chosen the option -> (" + choice + ")");
- switch (choice) {
- case 1:
- System.out.println("Please enter the value you wish to be squared");
- value = scan.nextInt();
- System.out.println("The squared value of " + value + " is " + (value * value)+"\n");
- break;
- case 2:
- System.out.println("Please enter the value you wish to be cubed");
- value = scan.nextInt();
- System.out.println("The cubed value of " + value + " is " + (value * value * value)+"\n");
- break;
- case 3:
- System.out.println("Please enter the value you wish to find the power of");
- int base = scan.nextInt();
- System.out.println("Please enter the power");
- int power = scan.nextInt();
- System.out.println("The squared value of " + base + " is " + Math.pow(base,power )+"\n");
- break;
- case 4:
- System.out.println("Thank you for using the service\nProgram terminating\n..........."+"\n");
- flag = false;
- break;
- default:
- System.out.println("Please enter a valid option"+"\n");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment