Created
January 28, 2021 16:12
-
-
Save BT-ICD/82c40b578977b39b300944ad43da93ab to your computer and use it in GitHub Desktop.
Example to learn about tracing - Conditional Execution and Math Operator in JAVA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DetermineOutputDemo { | |
public static void main(String[] args) { | |
outputDemo7(); | |
} | |
static void outputDemo1(){ | |
//Output x is :2 | |
int x; | |
x = 3*4%5; | |
System.out.println("x is :" + x); | |
} | |
static void outputDemo2(){ | |
//Reference:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html | |
// multiplicative * / % | |
// additive + - | |
//7*8 = 56 --> 56/5 = 11 -->11%10 =1 3+4-(1) | |
//x is 6 | |
int x; | |
x= 3+4-7*8/5%10; | |
System.out.println("x is :" + x); | |
} | |
static void outputDemo3(){ | |
//x is 5 (4 + 1=5) | |
int x; | |
x = 4 %5 + 6%5; | |
System.out.println("x is :" + x); | |
} | |
static void outputDemo4(){ | |
//Output is true --> (true and (true and true)) | |
int x=10, y=5; | |
boolean p ,q; | |
p= x>9; | |
q = x>3 && y!=3; | |
if(p && q){ | |
System.out.println("True"); | |
} | |
else | |
{ | |
System.out.println("False"); | |
} | |
} | |
static void outputDemo5(){ | |
//Output x is 0 y is 10 z is 8 | |
int x=10,y,z; | |
z=y=x; | |
//10 10 10 | |
System.out.println("x is " + x + " y is " + y + " z is " + z); | |
y=x--; | |
//9 10 10 | |
System.out.println("x is " + x + " y is " + y + " z is " + z); | |
z=--x; | |
//8 10 8 | |
System.out.println("x is " + x + " y is " + y + " z is " + z); | |
x= --x - x--; | |
//0 10 8 | |
//-1 7-8-- --> 7 - 7 -- > 0 | |
System.out.println("x is " + x + " y is " + y + " z is " + z); | |
} | |
static void outputDemo6(){ | |
//Output b is 100 c is 10 | |
int a=500,b=100,c=10; | |
if(!(a>=400)){ | |
b=300; | |
c=200; | |
} | |
System.out.println("b is " + b + " c is " + c); | |
} | |
static void outputDemo7(){ | |
//Output b is 20 and c is 40 | |
int a =10,b=20,c=30; | |
if(a>=100) | |
b=b++; | |
c=40; | |
System.out.println("b is " + b + " c is " + c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment