Question:
Struggling with Java programming?
2008-03-11 22:00:42 UTC
Hey everyone! Any help would be GREATLY appreciated :)

True/False

-The operators != and == have the same order of precedence

-A for loop is a post-test loop.

-All switch cases include a break statement.

-An else statement must be paired with an if statement

-A compound statement or block of statements is treated as a single statement.

Multiple Choice...

for(i = 1; i < 20; i++)
System.out.println(“Hello World”);

System.out.println(“!”);

-According to the code above, how many times will Hello World be printed?
a.1 c. 19
b.18 d. 20

-According to the code above, how many times will the ! be printed?
a.1 c. 19
b.18 d. 20

int x = 0;
for(i = 0; i <4; i++);
x++;
if(x = = 3)
System.out.println(“*”);

What is the output of the code above?
a.* c. ***
b.** d. There is no output

int x = 5;
int y = 30;

do
x = x * 2;
while(x < y);

-How many times does the statement above execute?

-If y = 0, how many times would the loop above execute?
Four answers:
Alex M
2008-03-11 22:09:25 UTC
This seems A LOT like homework that you should be doing yourself. Also they seem fairly simple if you have an understanding of programming in general. Sorry but do it yourself and learn something (Last time I helped someone I got "yelled" at).



if(x = = 3) should be written if(x == 3).



Good Luck!
Rajat
2008-03-11 22:31:30 UTC
Here's the solution:





-The operators != and == have the same order of precedence



-A for loop is a post-test loop. (False) - A For loop tests the condition before executing the body



-All switch cases include a break statement. (False) A Case may/may not incllude a break statement



-An else statement must be paired with an if statement (True)



-A compound statement or block of statements is treated as a single statement. (False)



Multiple Choice...



for(i = 1; i < 20; i++)

System.out.println(“Hello World”);



System.out.println(“!”);



-According to the code above, how many times will Hello World be printed?

a.1 c. 19

b.18 d. 20



Answer : c- 19 Times



-According to the code above, how many times will the ! be printed?

a.1 c. 19

b.18 d. 20



Answer : a - 1 Time



int x = 0;

for(i = 0; i <4; i++);

x++;

if(x = = 3)

System.out.println(“*”);



What is the output of the code above?

a.* c. ***

b.** d. There is no output



Ansrwe: d- There is no output. REASON. The for statement is terminated with a semi-colon. Hence, x will only be incremented once, making its value as 1. So, the condition (x==3) fails, and as a result, no output is produced



int x = 5;

int y = 30;



do

x = x * 2;

while(x < y);



-How many times does the statement above execute?



Answer: 3 times. (First Time, x = 10; Second Time, x = 20; Third Time, x = 40)



-If y = 0, how many times would the loop above execute?

Answer: 1 Time. The do while loop always executes once, irrespective of the condition specified.
2008-03-11 22:29:13 UTC
I agree with the other poster...you will never figure out programming if we do it for you... but i will give you two answers.



hello world is printed out 19 times....1 to 1less than 20 is 19, so 1 to 19 is nineteen times



and the ! is only printed out once because it is outside the loop....if you don't have {} to include things in the loop, in java only the first statement after the loop will be included
2008-03-12 00:46:57 UTC
Most of the answers are not correct, so either do your homework yourself or else you may contact a java expert live at website like http://askexpert.info/ .


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...