Advertisement
TheBeastOver9000

I Was Bored

May 29th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.49 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3.  
  4. class Calculator{
  5.     public static double calculateInput(int num1, char expr, int num2){
  6.         double result;
  7.         final double pi = 3.14;
  8.         switch(expr){
  9.             case '+':
  10.                 result = num1 + num2;
  11.                 return result;
  12.             case '-':
  13.                 result = num1 - num2;
  14.                 return result;
  15.             case 'x':
  16.             case '*':
  17.                 result = num1 * num2;
  18.                 return result;
  19.             case ':':
  20.             case '/':
  21.                 result = num1 / num2;
  22.                 return result;
  23.             case '%':
  24.                 result = num1 % num2;
  25.                 return result;
  26.             default:
  27.                 System.out.println("Invalid Expression");
  28.                 return 0;
  29.         }
  30.     }
  31. }
  32.  
  33. class Variables{
  34.     public static void printVariables(){
  35.         char[] alphabet = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  36.         for (int i = 0; i < 26; i++) {
  37.             for (int j = 0; j < 26; j++) {
  38.                 for (int k = 0; k < 26; k++) {
  39.                     System.out.print(alphabet[i]);
  40.                     System.out.print(alphabet[j]);
  41.                     System.out.print(alphabet[k]);
  42.                     System.out.print(", ");
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50. public class Main {
  51.     static Scanner sc = new Scanner(System.in);
  52.     public static void main(String[] args){
  53.         boolean a;
  54.         String lol;
  55.         System.out.print("Enter a boolean value: ");
  56.         a = sc.nextBoolean();
  57.         if (a){
  58.             System.out.println("It'll give you all variables name. Do you want it?");
  59.             lol = sc.next();
  60.             if(lol.equals("yes") || lol.equals("Yes") || lol.equals("YES")) Variables.printVariables();
  61.             else System.out.println("It won't give you all variables name");
  62.         }
  63.         System.out.println("Enter an expression");
  64.         int numb1 = sc.nextInt();
  65.         char oper;
  66.         do{
  67.             int uio = 0;
  68.             oper = sc.next().charAt(uio);
  69.             ++uio;
  70.         }while('1' == oper || '2' == oper || '3' == oper || '4' == oper || '5' == oper || '6' == oper || '7' == oper || '8' == oper || '9' == oper || '0' == oper);
  71.         int numb2 = sc.nextInt();
  72.         System.out.println(Calculator.calculateInput(numb1, oper, numb2));
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement