fork download
  1. import java.util.Scanner ;
  2.  
  3. class Ideone
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. Scanner lineScanner = new Scanner(System.in);
  9. double result = lineScanner.nextInt();
  10. lineScanner.nextLine(); // skip this DataRow?
  11.  
  12.  
  13. while (lineScanner.hasNextLine())
  14. {
  15. String DataRow= lineScanner.nextLine();
  16. if (DataRow.isEmpty())
  17. {
  18. System.out.print("result ="+ result );
  19. break;
  20. }
  21.  
  22. String[] cells = DataRow.split(" ");
  23.  
  24. int value = Integer.parseInt(cells[1]);
  25.  
  26. char ch =cells[0].charAt(0);
  27. switch (ch)
  28. {
  29. case '+':
  30. result += value ;
  31. break ;
  32. case '-':
  33. result -= value ;
  34. break ;
  35. case '*':
  36. result *= value ;
  37. break ;
  38. case '%':
  39. result %= value ;
  40. System.out.print("case % result ="+ result );
  41. break ;
  42. default :
  43. value = 0;
  44. break;
  45. }
  46. System.out.print(" value ( result) = "+ value +"("+ result + ")" );
  47. }
  48. System.out.print("finally result ="+ result );
  49. }
  50. }
  51.  
Success #stdin #stdout 0.17s 39344KB
stdin
10
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
* 10000000
% 100
stdout
 value ( result) = 10000000(1.0E8) value ( result) = 10000000(1.0E15) value ( result) = 10000000(1.0E22) value ( result) = 10000000(1.0E29) value ( result) = 10000000(9.999999999999999E35) value ( result) = 10000000(9.999999999999999E42) value ( result) = 10000000(9.999999999999999E49) value ( result) = 10000000(9.999999999999999E56) value ( result) = 10000000(9.999999999999999E63) value ( result) = 10000000(9.999999999999999E70) value ( result) = 10000000(1.0E78) value ( result) = 10000000(1.0E85) value ( result) = 10000000(1.0E92) value ( result) = 10000000(1.0000000000000001E99) value ( result) = 10000000(1.0E106) value ( result) = 10000000(1.0E113) value ( result) = 10000000(1.0E120) value ( result) = 10000000(1.0E127) value ( result) = 10000000(1.0E134)case % result =84.0 value ( result) = 100(84.0)finally result =84.0