fork download
  1. package workshop1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  *
  7.  * @author Chichtorya
  8.  */
  9. public class Part2 {
  10.  
  11. public static void main(String[] args) {
  12. Scanner InPut = new Scanner(System.in);
  13. System.out.print("Input the number 1: ");
  14. float Num1 = InPut.nextFloat();
  15. System.out.print("Input the number 2: ");
  16. float Num2 = InPut.nextFloat();
  17. System.out.print("Input the number 3: ");
  18.  
  19. float Num3 = InPut.nextFloat();
  20. char ope1, ope2;
  21. System.out.print("Input the operator 1: ");
  22. ope1 = InPut.next().charAt(0);
  23. System.out.print("Input the operator 2: ");
  24. ope2 = InPut.next().charAt(0);
  25. float result = 0;
  26. if (((int) ope2 == 42 || (int) ope2 == 47) && ((int) ope1 == 43 || (int) ope1 == 45)) {
  27. result = cal(cal(Num2, Num3, (char) ope2), Num1, ope1);
  28.  
  29. } else {
  30. result = cal(cal(Num1, Num2, (char) ope1), Num3, ope2);
  31. }
  32. System.out.print(Num1 +""+ ope1 +""+ Num2 +""+ ope2 +""+ Num3 + "=" + result);
  33.  
  34. }
  35.  
  36. public static float cal(float a, float b, char c) {
  37.  
  38. float result = 0;
  39. switch (c) {
  40.  
  41. case '+':
  42. result = a + b;
  43.  
  44. break;
  45.  
  46. case '-':
  47. result = a - b;
  48.  
  49. break;
  50.  
  51. case '*':
  52. result = a * b;
  53.  
  54. break;
  55.  
  56. case '/':
  57. result = a / b;
  58.  
  59. break;
  60.  
  61. default:
  62. System.out.println("Invalid operator!");
  63. break;
  64. }
  65. return result;
  66. }
  67.  
  68. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: error: class Part2 is public, should be declared in a file named Part2.java
public class Part2 {
       ^
1 error
stdout
Standard output is empty