0% found this document useful (0 votes)
45 views1 page

JAVA Programming Activities

The document contains code examples that demonstrate Java programming concepts like arithmetic operations, if/else conditional logic, and string output. Example 1 shows integer and floating point division and remainder operations. Example 2 checks for factors of a number using short-circuit logic. Example 3 outputs formatted text strings. The predicted output is provided for each example.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views1 page

JAVA Programming Activities

The document contains code examples that demonstrate Java programming concepts like arithmetic operations, if/else conditional logic, and string output. Example 1 shows integer and floating point division and remainder operations. Example 2 checks for factors of a number using short-circuit logic. Example 3 outputs formatted text strings. The predicted output is provided for each example.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

JAVA Programming Activities:

class Example1 { Predicted Output:


public static void main(String args[]) { First Line
int iresult, irem; Second Line
double dresult, drem; A B C
iresult = 10 / 3; D E F
irem = 10 % 3; .....................................................................................
dresult = 10.0 / 3.0; class LogicTable {
drem = 10.0 % 3.0; public static void main(String args[]) {
System.out.println("Result and remainder of 10 / boolean p, q;
3: " + iresult + " " + irem); System.out.println("P\tQ\tPANDQ\tPORQ\tPXORQ\t
NOTP");
System.out.println("Result and remainder of 10.0 /
p = true; q = true;
3.0: " + dresult + " " + drem);
System.out.print(p + "\t" + q +"\t");
}}
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
Predicted Output: p = true; q = false;
Result and Remainder of 10/3: 3 1 System.out.print(p + "\t" + q +"\t");
Result and Remainder of 10.0/3.0: System.out.print((p&q) + "\t" + (p|q) + "\t");
3.3333333333333335 1 System.out.println((p^q) + "\t" + (!p));
.................................................................................. p = false; q = true;
class Example2 { System.out.print(p + "\t" + q +"\t");
public static void main(String args[]) { System.out.print((p&q) + "\t" + (p|q) + "\t");
int n, d; System.out.println((p^q) + "\t" + (!p));
n = 10; p = false; q = false;
d = 2; System.out.print(p + "\t" + q +"\t");
if(d != 0 && (n % d) == 0) System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println(d + " is a factor of " + n); System.out.println((p^q) + "\t" + (!p));
d = 0; // now, set d to zero // Since d is zero, the }}
second operand is not evaluated.
if(d != 0 && (n % d) == 0) Predicted Output:
System.out.println(d + " is a factor of " + n); P Q PANDQ PORQ PXORQ NOTP
true true true true false false
/* Now, try same thing without short-circuit true false false true true false
operator. This will cause a divide-by-zero error. */ false true false true true true
false false false false false true
if(d != 0 & (n % d) == 0) ----------------------------------------------------------------------
System.out.println(d + " is a factor of " + n);
}} Subject/Course: _____________________________

Predicted Output: Student’s Name: ____________________________


2 is a factor of 10
..................................................................................... Date: _____________________________________
class Example3 {
public static void main(String args[]) Start Time: ________________________________
{ System.out.println("First line\nSecond line");
System.out.println("A\tB\tC"); Time Finished: _____________________________
System.out.println("D\tE\tF") ;
}} Score: _________________________

Checked by: _______________________________

You might also like