Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C Sc 127A Practice Test Solutions, Exams of Computer Science

The answers to the multiple choice questions and the output of certain java code snippets from a c sc 127a practice test. It includes solutions for logical comparisons, conditional statements, and a looping example.

Typology: Exams

Pre 2010

Uploaded on 08/31/2009

koofers-user-6lu
koofers-user-6lu 🇺🇸

10 documents

1 / 2

Toggle sidebar

Partial preview of the text

Download C Sc 127A Practice Test Solutions and more Exams Computer Science in PDF only on Docsity! C Sc 127A Practice Test, Spring 05 Answers int n1 = 20; int n2 = 40; a. __true_____ n1 < n2 b. __true_____ n1 != n2 c. __false_____ n1 != n2 - 20 d. __false____ 2 * n1 < n2 e. ____true_______ n1 > n2 || n2 > n1 f. ____false_______ n1 > n2 && n2 > n1 g. ____true_______ n2 >= 0 && n2 <= 100 h. ____true_______ ! "abc".equals("def"); 2. if(option != 'A' && option != 'D' && option != 'P') System.out.println ("Invalid option"); 3. Write the output generated by the following Java code (6pts) int j = 5; int k = 3; if(j > 0 || k < j) System.out.println("one"); if(k != j && k < 0) System.out.println("two"); else System.out.println("three"); 4. ONE POSSIBLE SOLUTION: assertEquals( "A", lg(101)); assertEquals( "A", lg(100)); assertEquals( "A", lg(90)); assertEquals( "B", lg(80)); assertEquals( "C", lg(70)); assertEquals( "D", lg(60)); assertEquals( "E", lg(0)); assertEquals( "?", lg(-1)); 5. ONE POSSIBLE SOLUTION public String lg(double grade) { if(grade > 100 || grade < 0 ) return "?"; else if(grade >= 90) return "A"; else if(grade >= 80) return "B"; else if(grade >= 70) return "C"; else if(grade >= 60) return "D"; else return "E"; } } 6. How many times will each of the following loops execute the iterative part “zero,” and “infinite” … int n = 1000; int j = 0; while(j <= n) { System.out.print("Hello"); j++; } 1001 int j = 5; int n = 1; for(j <= n) { System.out.print("Hello"); j--; } 0 int j = 1; int n = 5; while(j <= n) { System.out.print("Hello "); n++; } forever // Tricky Question int j = 1; while(j <= 14); { System.out.print("Hello "); j = j + 3; } 0 1 one three
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved