Systemoutprintln 20 2 1 mark questionanswer sheet

This preview shows page 4 - 10 out of 16 pages.

System.out.println( 20 % 2 ); (1 mark)
Image of page 4

Subscribe to view the full document.

Question/Answer Sheet - Page 5 - CompSci 101 S1 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED i) What is printed by the following? System.out.println( 20 % 3 ); (1 mark) j) What is printed by the following? System.out.println( 20 % 30 ); (1 mark) k) What is printed by the following? System.out.println("Sum = " + 3 + 3.5); (2 marks) l) What is printed by the following? System.out.println("Sum = \" + 3 + 3.5"); (2 marks)
Image of page 5
Question/Answer Sheet - Page 6 - CompSci 101 S1 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED m) What is printed by the following? System.out.println("\\\"+"+"\\"); (2 marks) n) What is printed by the following? System.out.println(Math.max(Math.min(1,4), Math.max(1,2))); (2 marks) o) What is printed by the following? String x = "Hello"; String y = "Joe"; System.out.println(x.length() + y.length()); (2 marks)
Image of page 6

Subscribe to view the full document.

Question/Answer Sheet - Page 7 - CompSci 101 S1 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 2 (10 marks) Using the values given for the variables below, evaluate the following boolean expressions: boolean a = true; boolean b = false; boolean c = true; boolean d = false; int e = 3; int f = 5; (a) (a && b) || (a && c) (2 marks) (b) (a || b) && (b || d) (2 marks) (c) (a && !b) && !(!a || d) (2 marks) (d) (e >= f) || ((e+2) < f) (2 marks) (e) (e < f) && (f != e) (2 marks)
Image of page 7
Question/Answer Sheet - Page 8 - CompSci 101 S1 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 3 (10 marks) What is the output when the following code is executed? public class Q3{ public static void main(String[] args){ int num1 = 15; int num2 = 34; int num3; if (num1>4 && num2<22){ num3 = num2-num1; if (num3>30) System.out.println("output 1"); else if (num3>20) System.out.println("output 2"); else System.out.println("output 3"); System.out.println("output 4"); } else { num3 = num2+num1; if (num3<30) System.out.println("output 5"); else if (num3<50 || num3%2==1) System.out.println("output 6"); else System.out.println("output 7"); System.out.println("output 8"); } } } (10 marks)
Image of page 8

Subscribe to view the full document.

Question/Answer Sheet - Page 9 - CompSci 101 S1 C SURNAME: ...................................................... FORENAMES: ...........................................................
Image of page 9
Image of page 10
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, English-language films, ........., Black-and-white films, Given name

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern