theinhumaneme

main.java

Jul 13th, 2022
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class main {
  5.  
  6.     public static Scanner scan = new Scanner(System.in);
  7.  
  8.     public static void main(String[] args) {
  9.         // flag for infinite loop
  10.         boolean flag = true;
  11.         while (flag == true) {
  12.             System.out.println(
  13.                     "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");
  14.             int choice = scan.nextInt();
  15.         int value;
  16.             System.out.println("You have chosen the option -> (" + choice + ")");
  17.             switch (choice) {
  18.                 case 1:
  19.                     System.out.println("Please enter the value you wish to be squared");
  20.                     value = scan.nextInt();
  21.                     System.out.println("The squared value of " + value + " is " + (value * value)+"\n");
  22.                     break;
  23.  
  24.                 case 2:
  25.                     System.out.println("Please enter the value you wish to be cubed");
  26.                     value = scan.nextInt();
  27.                     System.out.println("The cubed value of " + value + " is " + (value * value * value)+"\n");
  28.                     break;
  29.                 case 3:
  30.                     System.out.println("Please enter the value you wish to find the power of");
  31.                     int base = scan.nextInt();
  32.                     System.out.println("Please enter the power");
  33.                     int power = scan.nextInt();
  34.                     System.out.println("The squared value of " + base + " is " + Math.pow(base,power )+"\n");
  35.                     break;
  36.                 case 4:
  37.                     System.out.println("Thank you for using the service\nProgram terminating\n..........."+"\n");
  38.                     flag = false;
  39.                     break;
  40.                 default:
  41.                     System.out.println("Please enter a valid option"+"\n");
  42.                     break;
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment