Advertisement
476179

OperatorPresidence

Sep 30th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package lessons;
  2.  
  3. public class OperatorPresidence
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. System.out.println("Ex1");
  9. int ans, x , y ;
  10. x = 2 ;
  11. y = 3 ;
  12. ans = 17 + x + 21 + y;
  13. System.out.println("answer is : "+ans);
  14.  
  15. //-----------------------------------------------
  16.  
  17. System.out.println("\nEx2");
  18. double out;
  19. out = 12 + 6 /3;
  20. System.out.println("outcome is : "+ out);
  21.  
  22. //-----------------------------------------------------
  23.  
  24. System.out.println("\nEx3");
  25. int val1 = 5 + 2 * 4;
  26. System.out.println("value1 = "+val1);
  27.  
  28. int val2 = 10/2*3;
  29. System.out.println("value2 = "+val2);
  30.  
  31. int val3 = 8+12*2-4;
  32. System.out.println("value3 = "+ val3);
  33.  
  34. int val4 = 4 + 17 % 2-1;
  35. System.out.println("value4 = "+ val4);
  36.  
  37. int val5 = 6-3*2+7-1;
  38. System.out.println("value5 = "+ val5);
  39.  
  40. int val6 = 6/3*2%7-1;
  41. System.out.println("value6 = "+ val6);
  42.  
  43. //division and multipication have same
  44. //presidence so they are done same time left to right
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement