Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- public class OperatorPresidence
- {
- public static void main(String[] args)
- {
- System.out.println("Ex1");
- int ans, x , y ;
- x = 2 ;
- y = 3 ;
- ans = 17 + x + 21 + y;
- System.out.println("answer is : "+ans);
- //-----------------------------------------------
- System.out.println("\nEx2");
- double out;
- out = 12 + 6 /3;
- System.out.println("outcome is : "+ out);
- //-----------------------------------------------------
- System.out.println("\nEx3");
- int val1 = 5 + 2 * 4;
- System.out.println("value1 = "+val1);
- int val2 = 10/2*3;
- System.out.println("value2 = "+val2);
- int val3 = 8+12*2-4;
- System.out.println("value3 = "+ val3);
- int val4 = 4 + 17 % 2-1;
- System.out.println("value4 = "+ val4);
- int val5 = 6-3*2+7-1;
- System.out.println("value5 = "+ val5);
- int val6 = 6/3*2%7-1;
- System.out.println("value6 = "+ val6);
- //division and multipication have same
- //presidence so they are done same time left to right
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement