Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C$140 Assignment3-Questions [Compatibility Mode ailngs Review View Acrobat Shape

ID: 3701197 • Letter: C

Question



C$140 Assignment3-Questions [Compatibility Mode ailngs Review View Acrobat Shape Format Table Design Layout AaBbC AaBbCeD Normal Heading 1 Heading 2 Question One 1 Marks Suppose that x is declared as an integer and contain your last id number.If your last id ramming number is equal zero, x will contain the previous number Examples: syntax, If your id 160067123, so x -3 If your id 160067120, so x -2 nal nt, controt If your id 160067600, so x-6 s and res in create a 1) What is the output of the following snipped code? n based on System.out.printin("My id number is "x) ation for (int j.1; j

Explanation / Answer

1.

(a)

System.out.println("My id number is "+x); // this will print My id number is <value of x>

// loop prints the multiplication table of 1..x upto 3 values in each line

for(int i=1;i<=x;i++)

{

for(int j=1;j<=3;j++)

System.out.print(i*j+" ");

System.out.println();

}

For the value of x=3, the output will be :

My id number is 3

1 2 3 // prints multiplication table of 1 upto 3 values

2 4 6 // prints multiplication table of 2 upto 3 values

3 6 9 // prints multiplication table of 3 upto 3 values

(b)

System.out.println("My id number is "+x); // this will print My id number is <value of x>

// loop that print "#" i number of times ending with & in each line x-times

for(int i=0;i<x;i++)

{

for(int j=0;j<i;j++)

System.out.print("#");

System.out.print("& ");

}

For the value of x=3, the output will be :

My id number is 3

&

#&

##&