Arithmetic Demo

//ACTIVITY 1 //Programmed by

:

public class ArithmeticDemo { public static void main(String[] args){ //a few numbers int i = 37; int j = 42; double x = 27.475; double y = 7.22; System.out.println("Variable values..."); System.out.println(" i = " + i); System.out.println(" j = " + j); System.out.println(" x = " + x); System.out.println(" y = " + y); System.out.println("Adding..."); System.out.println(" i + j = " + (i + j)); System.out.println(" x + y = " + (x + y)); //subtracting numbers System.out.println("Subtracting..."); System.out.println(" i - j = " + (i – j)); System.out.println(" x - y = " + (x – y)); //multiplying numbers System.out.println("Multiplying..."); System.out.println(" i * j = " + (i * j)); System.out.println(" x * y = " + (x * y)); //dividing numbers System.out.println("Dividing..."); System.out.println(" i / j = " + (i / j)); System.out.println(" x / y = " + (x / y)); //computing the remainder resulting from dividing // numbers System.out.println("Computing the remainder..."); System.out.println(" i % j = " + (i % j)); System.out.println(" x % y = " + (x % y)); //mixing types System.out.println("Mixing types..."); System.out.println(" j + y = " + (j + y)); System.out.println(" i * x = " + (i * x)); } }

Program Output .

out.println(" j > i = "+(j>i)).//false } } . System.//false System.out. System.out.out.out.println(" k < j = "+(k<j)).println(" k >= j = "+(k>=j)).//ACTIVITY 2 //Programmed by: public class RelationalDemo{ public static void main(String[] args){ //a few numbers int i = 37.").").println("Not equal to.out.println(" i = " +i).//false //less than or equal to System.println("Less than..//false //greater than or equal to System.println(" k = " +k)..//true //equal to System.println("Less than or equal to.println(" i <= j = "+(i<=j)).println(" i == j = " + (i==j))...out.//false System.println("Variable values.println("Greater than or equal to.out.out."). System..println(" k != j = " + (k!=j)). System..out.out.println(" i != j = " + (i!=j))..println(" k == j = " + (k==j)).println(" i < j = "+(i<j)).out.")..//true System.out.out.println("Equal to.out. int k = 42.println(" j <= i = "+(j<=i)).out.println(" k <= j = "+(k<=j)).//false System. //greater than System.println(" i >= j = "+(i>=j))."). System..out.//true System.//true System.//true //not equal to System.println(" k > j = "+(k>j))..//true System.//false System.out.. System. System..println(" j >= i = "+(j>=i)).//true System.println(" j < i = "+(j<i))..out.//true //less than System. int j = 42.println(" j = " +j).").//false System.out.println(" i > j = "+(i>j)).out. System.out.").out..println("Greater than. System.out.out.out. System.

Program Output .

println(i).println(test).out. } } . System.println(i).out. System.println(j).out.out.println(j).out.println(j). int j = 10.out.out.out. //demonstrate && test = (i > 10) && (j++ > 9). //demonstrate || test = (i < 10) || (j++ > 9). int j = 10. //demonstrate | test = (i < 10) | (j++ > 9). System. System.println(j). System. boolean test= false.println(test).Write the output of the following programs //ACTIVITY 3 //Programmed by: public class TestAND { public static void main( String[] args ){ int i = 0. System.out.println(i). System.println(test). System. System.println(i). System. boolean test= false.out. //demonstrate & test = (i > 10) & (j++ > 9). System.out.out. } } //ACTIVITY 4 //Programmed by: public class TestOR { public static void main( String[] args ){ int i = 0.println(test). System.

.

println(!val2). System.out. val1 = false.out. boolean val2 = true.println(val1 ^ val2).out. val1 = true.out. System. System. val2 = false.println( status ). val2 = true.out. } } . val1 = false. } } //ACTIVITY 7 //Programmed by: public class ConditionalOperator { public static void main( String[] args ){ String status = "". System. val2 = false.out. System. //get status of the student status = (grade >= 60)?"Passed":"Fail".//ACTIVITY 5 //Programmed by: public class TestXOR { public static void main( String[] args ){ boolean val1 = true.println(val1 ^ val2). //print status System.println(val1 ^ val2). boolean val2 = false.println(val1 ^ val2). int grade = 80.out. System. } } //ACTIVITY 6 //Programmed by: public class TestNOT { public static void main( String[] args ){ boolean val1 = true.println(!val1).

Sign up to vote on this title
UsefulNot useful