0% found this document useful (0 votes)
4 views

Java - Review 1

The document is a test review for a Computer Science class, containing various code snippets and their expected outputs based on conditional statements and loops. It includes examples of if-else statements, comparisons, and for loops, with instructions for determining the output of each segment. The review is intended for students to complete before their test.

Uploaded by

arya.santosh2007
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)
4 views

Java - Review 1

The document is a test review for a Computer Science class, containing various code snippets and their expected outputs based on conditional statements and loops. It includes examples of if-else statements, comparisons, and for loops, with instructions for determining the output of each segment. The review is intended for students to complete before their test.

Uploaded by

arya.santosh2007
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/ 5

Computer Science Test Review Name _______________

Review is due for a grade before your test


1. int SAT = 1000;
if (SAT >= 1100)
System.out.println(“Admitted”);
else
System.out.println(“Rejected”);

2. int SAT = 1200;


if (SAT >= 1100){
System.out.println(“Admitted”);
}
else
System.out.println(“Rejected”);

3. int x = 100;
int y = 50;
if (x == y){
System.out.println("Hello");
}

4. int x = 100;
int y = 100;
if (x == y){
System.out.println("Hello");
}

5. int x = 100;
int y = 101;
if (x > y)
System.out.println("Hello");
else
System.out.println("Goodbye");

6. int x = 100;
int y = 101;
if (x < y){
System.out.println("Hello");
}
else {
System.out.println("Goodbye");
}

Assume these statements happen before each segment below.


What does each problem below output? (Write “Nothing” if nothing is output).

int MAX = 25, LIMIT = 100;


int num1 = 12, num2 = 25, num3 = 87;
Computer Science Test Review Name _______________
Review is due for a grade before your test

14. if (num2 < num1)


if (num3 < LIMIT){
System.out.println ("apple");
}
else {
System.out.println ("orange");
}
System.out.println ("pear");

15. if (num3 == 87)


{
if (num2 != MAX)
System.out.println ("apple");
}
else
System.out.println ("orange");
System.out.println ("pear");

16. if (num1+num2 > num3){


System.out.println ("apple");
}
else if (num2*LIMIT != 3298){
System.out.println ("orange");
}

17. if (LIMIT%MAX == 3)
System.out.println ("apple");
else if (num2 == MAX)
System.out.println ("orange");
else
System.out.println ("pear");
Computer Science Test Review Name _______________
Review is due for a grade before your test
18. if (num3 >= MAX)
{
if (MAX/num2 == 1){
System.out.println ("apple");
}
System.out.println ("orange");
if (LIMIT-num3 > num1+2){
System.out.println ("pear");
}
else {
System.out.println ("banana");
System.out.println ("kiwi");
}
}
else if (num2*2 == MAX*2){
System.out.println ("grapefruit");
}
else {
System.out.println ("lime");
}
System.out.println ("coconut");

19. if (num2 > num1 && LIMIT != 100)


System.out.println ("apple");
System.out.println ("orange");

20. if (num3 == num2 && MAX > 50)


System.out.println ("apple");
System.out.println ("orange");

21. if (num1 > 7 && LIMIT <= 100)


System.out.println ("apple");
System.out.println ("orange");

22. if (num3 < 40 || num3 > 50){


System.out.println ("apple");
}
System.out.println ("orange");

23. if (MAX == LIMIT || num1*2 == num2)


System.out.println ("apple");
System.out.println ("orange");
Computer Science Test Review Name _______________
Review is due for a grade before your test

Determine the output for each program segment that follows. If it has no output, print No
Output.

1. for (int x = 10; x <= 15; x++)


System.out.print("x = " + x);
2. for (int x = -1; x <= 8; x+=3)
System.out.print("x = " + x);

4. for (int x = 100; x >= 50; x-=10)


System.out.print("x = " + x);

5. for (int x = 1; x < 100; x*=3)


System.out.print("x = " + x);

6. for (int x = 200; x >= 25; x/=2)


System.out.print("x = " + x);

7. for (j = 1; j <= 6; j++)


System.out.print (“One ”);

8. for (j = 6; j >= 1; j--)


System.out.print (j + “ “);

9. for (x = 2; x < 12; x=x+2)


System.out.print (x + “ “);

10. for (x = 1; x <=11; x=x+2)


System.out.print (x + “ “);

11. for (x = 1; x <=7; x++);


System.out.print (“Hi “);

12. for (x = 6; x <=22; x = x + 3)


System.out.print (“six “);

13. for (x = 4; x <= 1000; x = x * 10)


System.out.print(x + “ “);

You might also like