473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Java questions

Question 1
class JMM102 {
public static void main(String args[]) {
for (int i = 0; i<5 ;i++) {
switch(i) {
case 0: System.out.print("v ");break;
case 1: System.out.print("w ");
case 2: System.out.print("x ");break;
case 3: System.out.print("y ");
case 4: System.out.print("z ");break;
default: System.out.print("d ");
}}}}
What is the result of attempting to compile and run the program?
a. Prints: v w x y z
b. Prints: v w x y z d
c. Prints v w x x y z z
d. Prints: v w w x y y z d
e. Prints: d d d d d d
f. Run-time error
g. Compile-time error
h. None of the above

Question 2
class JMM103 {
public static void main(String args[]) {
for (int i = 0; i < 5 ;i++) {
switch(i) {
0: System.out.print("v ");break;
1: System.out.print("w ");
2: System.out.print("x ");break;
3: System.out.print("y ");
4: System.out.print("z ");break;
}}}}
What is the result of attempting to compile and run the program?
a. Prints: v w x y z
b. Prints: v w x x y z z
c. Prints: v w w x y y z
d. Run-time error.
e. Compile-time error.
f. None of the above.

Question 3
class JMM107 {
public static void main(String[] args) {
boolean b = true;
if (b = false) {System.out.print("A");
} else if (b) {System.out.print("B");
} else {System.out.print("C");}
}}
What is the result of attempting to compile and run the program?
a. Prints: A
b. Prints: B
c. Prints: C
d. Run-time error
e. Compile-time error
f. None of the above

Question 4
class JMM108 {
static boolean b;
public static void main(String[] args) {
if (b) {System.out.print("A");
} else if (b = false) {System.out.print("B");
} else if (b) {System.out.print("C");
} else if (!b) {System.out.print("D");
} else {System.out.print("E");}
}}
What is the result of attempting to compile and run the program?
a. Prints: A
b. Prints: B
c. Prints: C
d. Prints: D
e Prints: E
f. Run-time error
g. Compile-time error
h. None of the above

Question 5
class JMM109 {
public static void main(String[] args) {
boolean b;
if (b = false) {System.out.print("A");
} else if (b) {System.out.print("B");
} else if (!b) {System.out.print("C");
} else {System.out.print("D");}
}}
What is the result of attempting to compile and run the program?
a. Prints: A
b. Prints: B
c. Prints: C
d. Prints: D
e. Run-time error
f. Compile-time error
g. None of the above

Question 6
class JMM122 {
public static void main (String[] args) {
for (int i = 0; i < 4; i++) {
switch (i) {
case 0: System.out.print("A");
case 1: System.out.print("B");
case 2: System.out.print("C");
}}}}
What is the result of attempting to compile and run the program?
a. Prints: ABC
b. Prints: ABCC
c. Prints: CBA
d. Prints: ABCBCC
e. Run-time error
f. Compile-time error
g. None of the above

Question 7
class JMM123 {
public static void main (String args[]) {
int i = 0, j = 0, k = 0;
label1:
for (int h = 0; h < 6; h++) {
label2:
do { i++; k = h + i + j;
switch (k) {
default: break label1;
case 1: continue label2;
case 2: break;
case 3: break label2;
case 4: continue label2;
case 5: continue label1;
}
} while (++j<5);
}
System.out.println(h + "," + i + "," + j);
}}
What is the result of attempting to compile and run the program?
a. Prints: 0,1,0
b. Prints: 0,2,1
c. Prints: 1,3,1
d. Prints: 2,4,1
e. Run-time error
f. Compile-time error
g. None of the above

Question 8
class JMM103 {
public static void main(String args[]) {
byte b = -1;
switch(b) {
case 0: System.out.print("zero "); break;
case 100: System.out.print("100 "); break;
case 1000: System.out.print("1000 "); break;
default: System.out.print("Default ");
}}}
What is the result of attempting to compile and run the program?
a. Prints: zero
b. Prints: 100
c. Prints: 1000
d. Prints: Default
e. Run-time error
f. Compile-time error
g. None of the above

Question 9
class JMM104 {
public static void main (String args[]) {
char c = 'b';
switch(c) {
case 'a': System.out.print("1");
case 'b': System.out.print("2");
case 'c': System.out.print("3");
default: System.out.print("4");
}}}
What is the result of attempting to compile and run the program?
a. Prints: 3
b. Prints: 34
c. Prints: 234
d. Prints: 1234
e. Run-time error
f. Compile-time error
g. None of the above

Question 10
class JMM105 {
public static void main(String args[]) {
int x = 6; int success = 0;
do {
switch(x) {
case 0: System.out.print("0"); x += 5; break;
case 1: System.out.print("1"); x += 3; break;
case 2: System.out.print("2"); x += 1; break;
case 3: System.out.print("3"); success++; break;
case 4: System.out.print("4"); x -= 1; break;
case 5: System.out.print("5"); x -= 4; break;
case 6: System.out.print("6"); x -= 5; break;
}
} while ((x != 3) || (success < 2));
}}
What is the result of attempting to compile and run the program?
a. Prints: 60514233
b. Prints: 6152433
c. Prints: 61433
d. Prints: 6143
e. Run-time error
f. Compile-time error

Question 11
class JMM106 {
public static void main(String args[]) {
int x = -5; int success = 0;
do {
switch(x) {
case 0: System.out.print("0"); x += 5; break;
case 1: System.out.print("1"); x += 3; break;
case 2: System.out.print("2"); x += 1; break;
case 3: System.out.print("3"); success++; break;
case 4: System.out.print("4"); x -= 1; break;
case 5: System.out.print("5"); x -= 4; break;
case 6: System.out.print("6"); x -= 5; break;
default: x += x < 0 ? 2 : -2;
}
} while ((x != 3) || (success < 2));
}}
What is the result of attempting to compile and run the program?
a. Prints: 60514233
b. Prints: 1433
c. Prints: 61433
d. Prints: 051433
e. Run-time error
f. Compile-time error

Question 12
class JMM124 {
public static void main(String args[]) {
int k;
for (int i=0, j=0; i<2; i++,j++) {System.out.print(i);} // 1
for (int i=0, k=0; i<2; i++,k++) {System.out.print(i);} // 2
for (int i=0, int j=0; i<2; i++,j++) {System.out.print(i);} // 3
}}
What is the result of attempting to compile and run the program?
a. Prints: 012345
b. Prints: 010101
c. Compile-time error at line 1
d. Compile-time error at line 2
e. Compile-time error at line 3
f. Run-time error
Feb 22 '07 #1
3 1366
r035198x
13,262 8TB
Question 1
class JMM102 {
public static void main(String args[]) {
for (int i = 0; i<5 ;i++) {
switch(i) {
case 0: System.out.print("v ");break;
case 1: System.out.print("w ");
case 2: System.out.print("x ");break;
case 3: System.out.print("y ");
case 4: System.out.print("z ");break;
default: System.out.print("d ");
}}}}
What is the result of attempting to compile and run the program?
a. Prints: v w x y z
b. Prints: v w x y z d
c. Prints v w x x y z z
d. Prints: v w w x y y z d
e. Prints: d d d d d d
f. Run-time error
g. Compile-time error
h. None of the above

Question 2
class JMM103 {
public static void main(String args[]) {
for (int i = 0; i < 5 ;i++) {
switch(i) {
0: System.out.print("v ");break;
1: System.out.print("w ");
2: System.out.print("x ");break;
3: System.out.print("y ");
4: System.out.print("z ");break;
}}}}
What is the result of attempting to compile and run the program?
a. Prints: v w x y z
b. Prints: v w x x y z z
c. Prints: v w w x y y z
d. Run-time error.
e. Compile-time error.
f. None of the above.

Question 3
class JMM107 {
public static void main(String[] args) {
boolean b = true;
if (b = false) {System.out.print("A");
} else if (b) {System.out.print("B");
} else {System.out.print("C");}
}}
What is the result of attempting to compile and run the program?
a. Prints: A
b. Prints: B
c. Prints: C
d. Run-time error
e. Compile-time error
f. None of the above

Question 4
class JMM108 {
static boolean b;
public static void main(String[] args) {
if (b) {System.out.print("A");
} else if (b = false) {System.out.print("B");
} else if (b) {System.out.print("C");
} else if (!b) {System.out.print("D");
} else {System.out.print("E");}
}}
What is the result of attempting to compile and run the program?
a. Prints: A
b. Prints: B
c. Prints: C
d. Prints: D
e Prints: E
f. Run-time error
g. Compile-time error
h. None of the above

Question 5
class JMM109 {
public static void main(String[] args) {
boolean b;
if (b = false) {System.out.print("A");
} else if (b) {System.out.print("B");
} else if (!b) {System.out.print("C");
} else {System.out.print("D");}
}}
What is the result of attempting to compile and run the program?
a. Prints: A
b. Prints: B
c. Prints: C
d. Prints: D
e. Run-time error
f. Compile-time error
g. None of the above

Question 6
class JMM122 {
public static void main (String[] args) {
for (int i = 0; i < 4; i++) {
switch (i) {
case 0: System.out.print("A");
case 1: System.out.print("B");
case 2: System.out.print("C");
}}}}
What is the result of attempting to compile and run the program?
a. Prints: ABC
b. Prints: ABCC
c. Prints: CBA
d. Prints: ABCBCC
e. Run-time error
f. Compile-time error
g. None of the above

Question 7
class JMM123 {
public static void main (String args[]) {
int i = 0, j = 0, k = 0;
label1:
for (int h = 0; h < 6; h++) {
label2:
do { i++; k = h + i + j;
switch (k) {
default: break label1;
case 1: continue label2;
case 2: break;
case 3: break label2;
case 4: continue label2;
case 5: continue label1;
}
} while (++j<5);
}
System.out.println(h + "," + i + "," + j);
}}
What is the result of attempting to compile and run the program?
a. Prints: 0,1,0
b. Prints: 0,2,1
c. Prints: 1,3,1
d. Prints: 2,4,1
e. Run-time error
f. Compile-time error
g. None of the above

Question 8
class JMM103 {
public static void main(String args[]) {
byte b = -1;
switch(b) {
case 0: System.out.print("zero "); break;
case 100: System.out.print("100 "); break;
case 1000: System.out.print("1000 "); break;
default: System.out.print("Default ");
}}}
What is the result of attempting to compile and run the program?
a. Prints: zero
b. Prints: 100
c. Prints: 1000
d. Prints: Default
e. Run-time error
f. Compile-time error
g. None of the above

Question 9
class JMM104 {
public static void main (String args[]) {
char c = 'b';
switch(c) {
case 'a': System.out.print("1");
case 'b': System.out.print("2");
case 'c': System.out.print("3");
default: System.out.print("4");
}}}
What is the result of attempting to compile and run the program?
a. Prints: 3
b. Prints: 34
c. Prints: 234
d. Prints: 1234
e. Run-time error
f. Compile-time error
g. None of the above

Question 10
class JMM105 {
public static void main(String args[]) {
int x = 6; int success = 0;
do {
switch(x) {
case 0: System.out.print("0"); x += 5; break;
case 1: System.out.print("1"); x += 3; break;
case 2: System.out.print("2"); x += 1; break;
case 3: System.out.print("3"); success++; break;
case 4: System.out.print("4"); x -= 1; break;
case 5: System.out.print("5"); x -= 4; break;
case 6: System.out.print("6"); x -= 5; break;
}
} while ((x != 3) || (success < 2));
}}
What is the result of attempting to compile and run the program?
a. Prints: 60514233
b. Prints: 6152433
c. Prints: 61433
d. Prints: 6143
e. Run-time error
f. Compile-time error

Question 11
class JMM106 {
public static void main(String args[]) {
int x = -5; int success = 0;
do {
switch(x) {
case 0: System.out.print("0"); x += 5; break;
case 1: System.out.print("1"); x += 3; break;
case 2: System.out.print("2"); x += 1; break;
case 3: System.out.print("3"); success++; break;
case 4: System.out.print("4"); x -= 1; break;
case 5: System.out.print("5"); x -= 4; break;
case 6: System.out.print("6"); x -= 5; break;
default: x += x < 0 ? 2 : -2;
}
} while ((x != 3) || (success < 2));
}}
What is the result of attempting to compile and run the program?
a. Prints: 60514233
b. Prints: 1433
c. Prints: 61433
d. Prints: 051433
e. Run-time error
f. Compile-time error

Question 12
class JMM124 {
public static void main(String args[]) {
int k;
for (int i=0, j=0; i<2; i++,j++) {System.out.print(i);} // 1
for (int i=0, k=0; i<2; i++,k++) {System.out.print(i);} // 2
for (int i=0, int j=0; i<2; i++,j++) {System.out.print(i);} // 3
}}
What is the result of attempting to compile and run the program?
a. Prints: 012345
b. Prints: 010101
c. Compile-time error at line 1
d. Compile-time error at line 2
e. Compile-time error at line 3
f. Run-time error
What are your solutions?
Feb 22 '07 #2
What are your solutions?
I havent solved all and is not sure about the answers

My answers are as follows:
1)c
2)e
3)c
4)d
5)c
6)d
7)-------------
8)f
9)c
10)
11)
Feb 23 '07 #3
r035198x
13,262 8TB
I havent solved all and is not sure about the answers

My answers are as follows:
1)c
2)e
3)c
4)d
5)c
6)d
7)-------------
8)f
9)c
10)
11)
You have 1 -6 right.

Can you see why 7 won't compile?
Feb 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

55
by: Elijah | last post by:
I have read many of the topics on learning C++ or Java first. It seems like everyone says something different. I would like to know if I should learn C++ or Java. First a little about myself. I...
8
by: Beatrice Rutger | last post by:
Hi, I am a previous Micro$oft desertee (moved from VB/VC++ to Java before this whole DOTNET thing) because I had several issues with Micro$oft. I am not completely in love with Windoze, but I...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
20
by: mayershome | last post by:
Hi! I'dont have any experiences in programming... what language should I start learning???? C? C++ or Java`? greetz
0
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate...
0
by: neelesh kumar | last post by:
sir, i have a java applet.i am using msaccess database . Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"). in my program i want to get questions from access table questions in a new frame...
1
by: saytri | last post by:
Hi i'm a student studying java (i'm still a beginner). i have a project were i have to do a quiz with a set of questions. So i think that i have to type the questions in a textfile for example in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.