UNIT 4 - Looping Constructs: TOPIC NAME:-Entry Controlled Loop: For Loop and While Loop (MCQS)
UNIT 4 - Looping Constructs: TOPIC NAME:-Entry Controlled Loop: For Loop and While Loop (MCQS)
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is? D 1 A~98~C~100~E~F~G~ 65~b~C~d~E~70~G~ 97~B~C~D~E~102~G~ a~66~C~68~E~f~G~
class ForTest{
public static void main(String[] args) {
for (char i = 'A'; i <= 'G'; i++) {
if (i % 5 == 0) {
System.out.print((char) (i - 'A' + 'a'));
}
246 4 else if (i % 2 == 0) {
System.out.print((int) i);
}
else {
System.out.print(i);
}
System.out.print('~');
} }}
The output of the following program is? A 1 Factorial of 5 is 1 Factorial of 5 is 120 Compilation Errors Factorial of 5 is 625
class Factorial {
public static void main(String s[]) {
int number = 5;
int factorial = 1;
247 4 for(int i = 2; i <= number; i++ ){
factorial *= factorial;
}
System.out.println("Factorial of 5 is " + factorial);
}
}
The output of the following program is? C 1 Compilation error since a=1 a=1 Compilation error since
class Test both a++ and b-- b=4 b=4 both a = 1 and b = 4
{ should not be present in a=2 a=2 should not be present
public static void main(String s[]) the iteration section (i.e b=3 b=3 in the initialization
{ after the second a=3 section (i.e before the
int a, b; semicolon) b=2 first semicolon)
248 4 for(a = 1, b = 4; a < b; a++, b--)
{
System.out.println("a = " + a);
System.out.println("b = " + b);
}
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is? A 1 Yes No Compilation Error Runtime Error
class ForTest{
public static void main(String args[]){
int number = 496;
int sum = 0;
for (int i = 1; i < number; i++)
249 4 {
if (number % i == 0)
sum = sum + i;
}
System.out.print((sum == number) ? "Yes" : "No");
}
}
The output of the following program is? D 1 i = 10 i = 10 Compilation Errors No Output
class ForSample { i=9 i=9
public static void main(String s[]) { i=8 i=8
for(int i = 10; i <= 5; i-- ) { i=7 i=7
System.out.println("i = " + i ); i=6 i=6
250 4
} i=5
} i=4
} i=3
i=2
i=1
The first expression in a for… loop is B 1 Step value of loop initial Value of the Condition statement None of the above
251 4
counter variable
The output of the following program is? B 1 0 5, 1 4, 2 3, 3 2, 4 1, 0 6, 1 5, 2 4, 3 3, 4 2, Some other output Compilation Error
class LoopExample
{
public static void main(String[] args)
{
252 4 for (char i = 0, j = 6; i < 5 && j > 0; i++, --j)
{
System.out.print((int) i + " " + (int) j + ", ");
}
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is? B 1 i = 15 j = 13 k = 759 i = 16 j = 16 k = 297 i = 15 j = 13 k = 808 Program goes into
class TestWhile { infinite loop
public static void main(String[] args)
{
int i = 1;
int j = 20;
int k = 31;
253 4 while (i < j) {
k += (i * j);
i = i * 2;
j--;
}
System.out.println("i = " + i + " j = " + j + " k = " + k);
}
}
The output of the following program is? D 1 26^25^24^23^22^21^20^1 224^196^168^1310^1012 224^196^168^1310^101 Some other output
class Test { 9^18 ^714^416^118^-220^ 2^714^
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following code : A 1 13 0 13 10 31 0 13
class MyClass{
public static void main(String args[])
{
int i = 3;
int j = 10;
while ((j != 0) && ((i / j) >= 0)) {
256 4
i = i + 1;
j = j - 1;
}
System.out.print(i+" ");
System.out.print(j);
}
}
What will be the output of following code? D 1 13 7 1 13 7 17 7 13
class MyClass{
public static void main(String args[])
{
for (int j = 5; j < 15; j+=2) {
257 4
if (j % 3 == 1)
System.out.print(j+ " ");
}
}
}
What is the output of the following code : C 0.5 1,2,3,4,5 infinite times 65,66,67,65,66,67 infinite B,B,B, infinite times A,A,A, infinite times
class MyClass { times
public static void main(String[] args) {
while(true)
{
258 4 int i=65;
i++;
System.out.print((char)i + ",");
i++;
}
}}
What is the output of the Java code snippet? C 0.5 vfx+3D vfx Compiler Error No Error but infinite
class Avatar2{ loop
public static void main(String [] args) {
int vfx;
for (vfx = 2; false ; vfx--)
259 4 {
System.out.print("vfx");
}
System.out.print("+3D");
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the code : D 0.5 97531 987654321 Error No Error but infinite
class Avatar{ loop
public static void main(String [] args) {
260 4 int imax;
for (imax = 9; imax!=0; imax--)
System.out.print(imax--);
}}
What is the output of the following code : D 0.5 0 3, 1 2, 2 1, 0 3, 1 2, 2 1 0 2, 1 1, 2 0, Compile time error
class Test{
public static void main(String[] args)
{
261 4 for (int a = 0, int b = 3; a < 3 && b > 0; a++, b--)
{System.out.print(a + " " + b + ", ");
}
}
}
What will be the output of the following program? D 0.5 DEF ABCDEF Run Time Error Compile time error
class Test{ public static void main(String args[]){
int m;
for(m=0;false;m++)
262 4 {
System.out.print("ABC");
}
System.out.print("DEF");
}}
What will be the output of the following program? A 0.5 LJU JAVA LJU LJ Error
class Test{ public static void main(String args[]){
int m = 0;
for(System.out.print("LJ");m<1;System.out.print("U"))
263 4 {
m++;
}
System.out.print(" JAVA");
}}
What will be the output of the following program? D 0.5 JAVA JAVALJU JAVA inifnite times Error
class Testwhile{ public static void main(String args[]){
while(true)
{
264 4
System.out.print("JAVA");
}
System.out.print("LJU");
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output for the following? C 0.5 10 0 1 Runs but No output
class Compute Printed
{
public static void main(String args[]){
int result, x;
x= 10;
265 4 result = 1;
while (x<10){
if (x%2==0)
result*=x;
++x; }
System.out.println(result);
}}
How many times does the following method print *? D 0.5 7 8 12 1
266 4 for (int i = 5; i <= 12; i++);
{System.out.print("*");}
What does the following code snippet prints? D 0.5 345678 Error It prints 3 4 5 in infinite It will print 3 in infinite
int x = 3; loop loop
while (x < 9)
267 4
{
System.out.print(x + " ");
}
What is the output of the below code snippet? A 0.5 4321 4321 321 321
int a=4;
while(a>0)
268 4 {
System.out.print(a + " ");
a--;
}
What will be the output of following Java program? D 0.5 LoopTest2Java LoopTest 2 LoopTest 2Java Error
class T2 {
public static void main(String[] args) {
System.out.print("Loop");
269 4
for (int i = 0; ; i++) {
System.out.print("Test 2");
}
System.out.print("Java");}}
The output of the following program is? D 0.5 l,l l,j ljHii Error
class Loop3 {
public static void main(String args[]) {
270 4
int a=1,b=2;
for(System.out.print("lj"); a>b ;System.out.print("Hii") )
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following code : class L5 { D 0.5 Hello Hi HelloHi Error
public static void main(String args[]) {
int a=1,b=2;
271 4 while(true) {
System.out.print("Hello");
} System.out.print("Hii");
}}
Choose correct answer from given options for below given programs. C 1 Output of Sample1 and Output of Sample2 and Output of all the three Sample2 does not
class Sample1 { Sample2 is same, but they Sample3 is same, but programs is same. compile since there is
public static void main(String s[]){ are different from they are different from no code before first
for(int i = 0; i <= 5; i++ ) { Sample3. Sample1. semicolon and no code
System.out.println("i = " + i ); } }}
after second semicolon.
class Sample2 {
public static void main(String s[]) {
int i = 0;
272 4 for( ;i <= 5; ) {
System.out.println("i = " + i );
i++; } }}
class Sample3 {
public static void main(String s[]) {
int i =0;
while(i <= 5){
System.out.println("i = " + i );
i++;}}}
What is the output of the following Java code snippet? D 1 i j 105 106
class MCQ
{
public static void main (String agrs[ ])
{
273 4 int j=0,k='i';
for(char i='j'; j<3; k++)
System.out.print(j=i);
}
}
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is? D 1 n=5 n=5 n=5 n=5
class Test { n=4 n=4 n=4
public static void main(String s[]) { n=3 n=3 n=3
int n = 5; n=2 n=2
do { n=1
275 4
System.out.println("n = " + n);
n--;
} while ( n < 2 );
}
}
What will be the output of the following program? D 0.5 LJUniversity LJ is printing inifnite LJUNIVERSITY Unreachable code :
class Test{ public static void main(String args[]){ times Error
do
{
276 4 System.out.print("LJ");
}
while(true);
System.out.print("University");
}}
What is the value of "age" in the below code with a DO-WHILE loop? C 0.5 19 20 21 22
int age=20;
do
277 4 {
age++;
}while(age<20);
System.out.print(age);
TOPIC NAME:- Nested Loops (MCQS)
The output of the following program is? C 1 5656 56 5566 Compilation error
class Test {
public static void main(String[] args) {
int i = 5;
while (i < 7) {
for (int k = 0; k < 2; k++) {
278 4
System.out.print(i);
}
i++;
}
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is? B 1 true true true Run time error
class Test { false false true
public static void main(String[] args) { true false true
boolean water = true;
while (water) {
System.out.println(water);
while (water) {
279 4
water = false;
System.out.println(water);
}
}
System.out.println(water);
}
}
The output of the following program is? B 1 sum = 336 sum = 45 sum = 359 Compilation errors
class TestFor {
public static void main(String s[]) {
int sum = 23;
for(int i = 2; i <= 5; i++ ) {
for(int j = 7; j <= 9; j++ ) {
280 4
sum = (i * j);
}
}
System.out.println("sum = " + sum);
}
}
The output of the following program is? C 1 Sum = 35 Sum = 576 Sum = 16 Error
class Loop1 {
public static void main(String s[]) {
int sum = 5;
int i = 1;
for( ; i < 4; ) {
for(int j = 1; j < 4; ) {
281 4 for(int k = 1; k < 4; k++) {
sum = (i * j);
i++;
j++;
k++;
}}}
System.out.println("Sum = " + sum);
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is? C 1 out = -6 out = -78 out = 48 Compilation Error
class OutPut {
public static void main(String[] args) {
int out = -15;
for (int i = 5; i < 7; i++) {
for (int j = 8; j >= 6; j--) {
if (i == j) break;
282 4 if (i > j) {
out += i + j;
}else {
out += j + i;
}
}}
System.out.println("out = " + out);
}}
What is the output of the following code : B 0.5 1,2,3,4,1,2,3,4, 1,2,3,4, 1,2,3,1,2,3, 1,2,3,
class MyClass {
public static void main(String[] args) {
int i=1, j=1;
while(i<3)
{
do
283 4
{
System.out.print(j + ",");
j++;
}while(j<4);
i++;
}
}}
What is the output of the following code: D 0.5 56789 567 55555 Compilation Error
class MyClass {
public static void main(String[] args) {
for (int i=0;i<5;i++)
{
284 4
for(int j=0;j<5;j++)
j++;
System.out.print(i + j);
}
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following code : C 0.5 7 9 10 11 6688 68 9999
class MyClass {
public static void main(String[] args) {
int i=1,j=1;
for (;i<3;i++)
285 4 {
for(;j<4;j++);
j++;
System.out.print(i + j+" ");
}
}}
What is the output of the following code : A 0.5 4 22 1133 11
class MyClass {
public static void main(String[] args) {
int i=1,j=1;
for (;i<3;i++)
{
while(j<3)
286 4 {
j++;
if(i==2 || j==2)
continue;
System.out.print(i + j+" ");
}
}
}}
What is the output of the following code : B 0.5 5 2 3 4
class MyClass {
public static void main(String[] args) {
int i=1;
int b=5;
do
287 4
while(b!=5)
i++;
while (false);
System.out.println(++i);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the Java code snippet? B 0.5 1 2 4 8
class Loop1 {
public static void main (String args[]) {
int i,j,k;
for (i=0; i< 3; i++) {
288 4 for(j=1;j<4;j++){
for (k=2; k<5; k++){
if ((i == j) && (j==k))
System.out.println (i);
}}}
}}
What is the output of the following code : C 0.5 1 infinite times 1 No Output Compile time error
class Test{ public static void main(String [ ] args) {
int I = 1;
289 4 do while ( I < 1 )
System.out.print(I); while ( I > 1 ) ;
}
}
What will be the output of the following program? D 0.5 LJ true true infinite times LJ Infinite Times
class Testdowhile{ public static void main(String args[]){
boolean b = true;
290 4 do while(b)
System.out.print("LJ");
while(true);
}}
What is the output of the following program : D 0.5 3 3,5,3 2 Error
class XYZ {
public static void main(String s[]) {
int x =2 ,y =5;
while(x<y) {
291 4 x++;
System.out.println(x);
for(int i=1; false; System.out.println(y))
{
System.out.println(x);
}}}}
TOPIC NAME:- Nested Loop (Programs)
WAP to print following pattern using loop statement for n row.
54321
4321
292 4 5
321
21
1
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
WAP to print following pattern using loop statement for n row.
1
AB
293 4 5
123
ABCD
12345
WAP to print following pattern using loop statement for n row.
12345
2345
294 4 5
345
45
5
WAP to print following pattern using loop statement for n row.
1
295 4 01 4
101
0101
Write a program for following given pattern using nested loops.
1
24
296 4 3
135
2468
13579
Write a program to print following pattern using nested loop. (use Scanner class for
input)
1
297 4 23 3
654
7 8 9 10
15 14 13 12 11
WAP to print following pattern using loop statement for 5 row.
L J L J L
L J L J
298 4 3
L J L
L J
L
TOPIC NAME:- break and continue Statements (MCQS)
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is? D 1 0 0 No Output Unreachable code
class Test { 1 Error
public static void main(String args[]){
for (int i = 0; i < 10; i+=2) {
if (i == 2){
break;
299 4 }
else {
continue;
}
System.out.print(i + " ");
}}
}
The output of the following program is? D 1 0 0 Compilation error Infinite Loop
class Test { 1 1
public static void main(String[] args) { 2 2
int i = 0; 3 3
while (i < 10) { 5
if (i == 4) { 6
300 4 i++; 7
continue; 8
} 9
System.out.println(i);
}
}
}
continue statement used for B 1 To continue to the next To stop the current To handle run time None of the above
line of code iteration and begin the error
301 4
next iteration from the
beginning
break statement is used for A 1 Breaks loop and goes to Does not break loop Exits the program. Starts from beginning
302 4 next statement after but starts new of program.
loop. iteration.
What will be the output of following code? C 1 3 0 2 Error: unreachable
class MyClass{ code
public static void main(String args[])
{
int i = 0;
303 4 for(i = 0; (i+=2)< 10; i++){
break;
}
System.out.println(i);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code? B 1 20 21 22 23 24 45 20 21 22 23 2445 21 22 23 24 45 46 2122 23 24 4546
class MyClass{
public static void main(String args[])
{
for(int i = 0; i < 40; i++){
304 4 if(i % 5 == 0){
System.out.print((i+=20));
continue;
}
System.out.print(" "+i);
}}}
What is the output of the following code : C 0.5 5 2 3 4
class Trial {
public static void main(String[] args) {
int i = 0;
for(i = 0;i< 3; i++){
305 4
continue;
}
System.out.println(i);
}
}
What is the output of the following code : B 0.5 123456 146 012 1246
class ChallangeYouCantSolveIt{
public static void main(String [] args) {
int x=0;
do{
x++;
306 4 System.out.print(x);
if(++x<3)
continue;
x++;
System.out.print(x);
}while(++x<5);
}}
What is the output of the following code : A 0.5 Avatar-2 The way The Avatar-2 The way of The way of water Avatar-2 of water The
class JamesCameron{ way of Water water way
public static void main(String [] args) {
int i=10;
307 4
for (System.out.print("Avatar-2");i>8;System.out.print(" The way"))
{i--;;continue;}
System.out.print(" of Water");
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following Program : D 0.5 12 14 16 13 15 Error 13
class MCQ{
public static void main(String[] args){
int i=12;
do{
++i;
308 4
if ( (i%2) == 0){
continue;}
System.out.print (i+ " ");
break;
}while(i<17);
}}
What is the output of these code : C 0.5 5 10 0 Error
class Test{ public static void main(String args[ ]){
int k = 50;
while(true)
{
309 4 if ( k < 4 )
break;
k = k-5;
}
System.out.println(k);
}}
What will be the output of the following program? A 0.5 7-8-9-10- 7-8-9-10 7-8- Compile time error
class Test{ public static void main(String args[ ]){
int marks=7;
boolean b=true;
for( ; b ; marks++)
310 4 {
System.out.print(marks+"-");
if (marks > 9)
break;
}
}}
What is the output of the below Java code snnipet? A 0.5 1,2,3,4, 1,2,3,4 1,2,3 1,2,3,
int score=1;
for(; true; score++)
{
311 4
System.out.print(score +",");
if(score > 3)
break;
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the Java code snippet? A 0.5 15,16,17,18,19,20,21, 15,16,17,18,19,20,21 15,16,17,18,19,20 Error
class OutPut
{
public static void main(String[] args)
{
int score=15;
312 4 for(; true; score++)
{
System.out.print(score +",");
if(score > 20)
break;
}
}
}
What will be the output of following Java program? D 0.5 1468 135 146 14
class T2 {
public static void main(String[] args) {
int x = 0;
do{
++x;
313 4
System.out.print(x);
if (x++<5)
continue;
++x;
System.out.print(x);
}while(++x<5); } }
What is the output of the following Java code snippet? C 1 P PQ PP Compile Error
class MCQ
{
public static void main (String agrs[ ])
{
char ch='P';
314 4 do{
System.out.print(ch);
if(ch=='P')
continue;
ch='Q';
}while(ch=='Q');
System.out.print(ch); } }
TOPIC NAME:- Mixed (MCQS)
315 4 Which of following loop is executed at least once? A 1 do-while for loop if while
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
import java.util.*; B 1 32 3 2 Comlipe Error
class MCQ {
public static void main(String agrs[]) {
int x = 2, y = 2;
do
; while (x < y++);
316 4
{
System.out.print(++x);
for (Scanner sc; x < y; System.out.print(y))
x++;
}
}
}
TOPIC NAME:- Mixed (Programs)
317 4 WAP to find out sum of first and last digit of a given number 5
WAP to find if the number is Armstrong Number or not. Example: - 153 is an
318 4 5
Armstrong Number.
Assume that you want to make the sum of 1 to 100. Give the necessary code to
319 4 perform the same using 4
(1) For loop (2) While loop (3) Do-while loop
WAP to print multiple of N from given range of unsigned integers. For example, if
320 4 N=5 and range is [17, 45] it prints 20, 25, 30, 35, 40, 45. Take input using Scanner 4
class.
321 4 WAP to find result of 1+3/5+5/7+7/9+... series. Print addition of first N part. 5
322 4 WAP to reverse a number. 4
Write a Java Program to determine whether a given number is a Disarium number
or not?
(Hint: A number is said to be the Disarium number when the sum of its digit raised
323 4 3
to the power of their respective positions is equal to the number itself)
Eg: Input: 135 => 1^1 + 3^2 + 5^3 = 135 => 135 is a Disarium number.
Input: 25 => 2^1 + 5^2 = 27 => 25 is not a Disarium number.
UNIT 5- Arrays
TOPIC NAME:- ONE DIMENSIONAL ARRAY ( MCQs)
Theoreteically no
limit.The only practical
324 5 What is the maximum number of dimensions an array may have? D 1 2 8 20
limit is memory size and
compilers
What is the output of JAVA Program.?
class ForEachLooP
{
public static void main(String args[])
325 5 B 1 238919 238919 10 Compiler Error
{ int[] scores = new int[10];
scores = new int[3]; scores = new int[] {2,3,8,9,1,9};
for(int score : scores){System.out.print(score);}
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of JAVA Program.?
class ArrJava {
public static void main(String args[]){
int a[] = {5,1,15,20,25};
int i,j,m;
326 5 A 1 3,2,15 2,3,20 2,1,15 1,2,5
i = ++a[1];
j = a[1]++;
m=a[i++];
System.out.println(i+","+j+","+m);
}}
What is the output of JAVA Program.?
class ArrJava {
public static void main(String args[]){
327 5 int a[] = {10,12,14}; a[0]=20; A 1 20 12 14 10 20 14 10 12 20 Compiler Error
int i=0;
while(i<3) {System.out.print(a[i]+" ");i++;}
}}
What is the output of JAVA Program.?
class ArrJava {
public static void main(String args[]){
328 5 int a[] = {10,12,14}; int i=0; D 1 14 12 10 10 10 10 10 12 14 Compiler Error
while(i<3)
{ System.out.println(i[a]); i++; }
}}
What is the output of JAVA Program.?
class ArrJava {
public static void main(String args[]){
329 5 B 1 20 30 40 21 31 41 21 30 40 Compiler Error
int a[] = {20,30,40}; int i=0;
while(i<3){ a[i]++;System.out.print(a[i]+" ");i++;}
}}
What is the output of JAVA Program.?
class ArrJava {
330 5 public static void main(String args[]) { D 1 1 2 4 Compiler Error
int a[] ; a[]={1,2,3,4}; System.out.println(a[0]);
}}
What is the output of JAVA Program.?
class ArrJava {
public static void main(String args[]) {
331 5 D 1 1,5 2,6 00 Compiler Error
int a[] = {1,2,3,4}; int b[4] = {5,6,7,8};
System.out.println(a[0]+","+b[0]);
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of JAVA Program.?
class ForEachLooP
{
public static void main(String args[]){
332 5 int[] scores = new int[10];System.out.print(scores.length); C 1 666 1035 1036 Compiler Error
scores = new int[3];System.out.print(scores.length);
scores = new int[] {215, 234, 218, 189, 221, 290};
System.out.print(scores.length);
}}
333 5 Array index start at B 1 1 0 User Defined None of the above
How many of the following are legal declarations?
String lion [] = new String[] {"lion"};
334 5 String tiger [] = new String[1] {"tiger"}; C 1 1 3 2 4
String bear [] = new String[] {};
String cat [] = new String[0] {};
How many of the following are legal declarations?
float[] lion = new float[];
335 5 float[] tiger = new float[1]; A 1 1 2 3 4
float[] bear = new[] float;
float[] cat = new[1] float;
Which is not a true statement about an array?
A. An array expands automatically when it is full.
336 5 B. An array is allowed to contain duplicate values. C 1 B C A D
C. An array understands the concept of ordered elements.
D. An array uses a zero index to reference the first element.
337 5 int x[] = { 22,33,44}. What will be value of x[4]? D 1 55 0 66 Run time error
int x[5] = {3,4,5}
338 5 D 1 0 4 5 compile time error
What will be the value of x[4]?
What is the output of JAVA Program.?
class Loop1 {
public static void main(String s[]) {
int x[]={1,2,3,4} ;
339 5 x[0] = x[1]++; B 0.5 4,4,5 3,4,5 3,3,5 5,4,3
x[2] = x[0]++ + x[1]++ ;
System.out.print(x[0]+",");
System.out.print(x[1]+",");
System.out.print(x[2]);
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of JAVA Program.?
class Array {
public static void main(String[] arg) {
int a[] = new int[5];
a= {11,12,13,14,15};
340 5 System.out.print(a[0]); B 0.5 111112 Compile time Error Run time Error 111213
int b = a[0]++;
System.out.print(b);
System.out.print(a[0]);
}
}
What is the output ?
class MCQ12{
public static void main(String args[])
{
int a[] = {12,200,20,2020,202};
341 5 A 0.5 200 2020 20 2020 200 202 12 200 20 2020
for(int i=0;i<4;i++){
System.out.print(a[++i]+" ");
}
}
}
What is the output?
class MCQ16{
public static void main(String args[])
{
int a[] = {10,20,30};
int i=1;
342 5 C 0.5 1030 102030 10230 10030
while(i<2){
++a[i];
i++;
}
System.out.print("10"+i+a[i]);
}
}
What will be the output?
class MCQ7{
public static void main(String args[])
{
int arr[] = new int[] {15 , 20, 8, 9, 7, 2, 25,89,90,100};
343 5 int n = 4; B 0.5 89 50 20 8
n = arr[arr[n] / 2];
System.out.println(arr[n] / 2);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
Find the output ?
class MCQ14{
public static void main(String args[])
{
344 5 int For[] = {10,20,30,40}; B 0.5 No output 1230 1200 620
int i = For[2]*(++For[3]);
System.out.print(i);
}
}
What is the output of the Java code snippet?
class ItIsEasy{
public static void main(String [ ] args) {
int i=5; int[ ] a= new int[i--];
345 5 char ch='b'; int[ ] b= new int[ch++]; B 0.5 68 69 67 Error
byte x=4;int[ ] c= new int[x++];
short s=30;int[ ] d= new int[s++];
System.out.println(a.length + b.length - c.length - d.length);
}}
346 5 What is the output of the Java code snippet? D 0.5 abc 102030 979899 Error
What is the output of the Java code snippet?
class NaturalNumbers {
public static void main(String[ ] args) {
int natural[ ] = new int[7];
347 5 for (int i = 1; i < 7; ++i) { D 0.5 10305 12 123456 000
System.out.print(natural[i]);
natural[i] = i;
i++;}
}}
What is the output of the following code?
class Test {
public static void main(String args[]) {
int arr[]={1,2,3,4};
int i=0;
348 5 int a[]=new int[5]; B 0.5 1,2, 0,0,0, 1,2 1,2,3
while(i<3){
a[i]=arr[i++];
System.out.print(a[i]+",");
}
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of following code?
class Test {
public static void main(String[] args) {
char ch[] = {'A', 'B', 'C'};
int i=0;
349 5 do B 0.5 A,B,C A,B,C, Compiler error A,A,A
{
System.out.print(ch[i] + ",");
i++;
}while(i < ch.length);
}}
What will be the output of below program?
class Test {
public static void main(String args[]) {
int i;
350 5 int a[]=new int[6]; C 0.5 000000 111111 100000 012345
a[0]=1;
for(i=0;i<6;i++)
System.out.print(a[i]);
}}
What is the output of the Java code snippet?
class ArrJava
{
public static void main(String args[])
{
351 5 B 0.5 1,5 Compile time error 0,0 2,6
int a[] = {1,2,3,4};
int b[4] = {5,6,7,8};
System.out.println(a[0]+","+b[0]);
}
}
What is the output of the Java code snippet?
class Test
{
public static void main(String args[])
{
double[] myList = {1, 5, 5, 5, 5, 1};
double max = myList[0];
352 5 A 0.5 1 0 2 3
int indexOfMax = 0;
for(int i = 1; i < myList.length; i++)
{
if(myList[i] > max) {
max = myList[i];
indexOfMax = i; } }
System.out.println(indexOfMax); } }
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the Java code snippet?
class MyClass {
public static void main(String args[]) {
int fact[]={0, 2, 4, 1, 3};
353 5 A 0.5 1 0 2 4
for (int n=0;n<fact.length;n++)
fact[n]=fact[(fact[n]+3)%fact.length];
System.out.print(fact[1]);
}}
What is the output of the Java code snippet?
class MyClass {
public static void main(String args[]) {
354 5 int fact[]=new int[5]; B 0.5 12345 00000 11111 55555
for (int num:fact)
System.out.print(num+" ");
}}
What is the output of the Java code snippet?
class MyClass {
public static void main(String args[]) {
355 5 A 0.5 0 1 -1 undefined
int[] balls = {};
System.out.print(balls.length);
}}
What is the output of the Java code snippet?
class MyClass {
public static void main(String args[])
{
int a[]={1,2,3,4,5};
356 5 C 0.5 1,2,3,4,5, 1,2,5,4,3, 1,2,3,5,5, 5,4,3,2,1
a[3]=a[4];
a[4]=a[3];
for(int num:a)
System.out.print(num+",");
}}
What is the output of the following Java program?
class T2 {
public static void main(String args[]) {
int[] scores = new
int[10];
System.out.print(scores.length);
357 5 B 0.5 1035 1036 1023 1025
scores = new int[3];
System.out.print
(scores.length);
scores = new int[]{215, 234, 218, 189, 221, 290};
System.out.print(scores.length);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following Java program?
class T2 {
public static void main(String[] args) {
int a[] = {1,0,2,1,0};
int temp = a[0];
for (int i=0;i<3;i++){
a[0] = a[i];
358 5 C 0.5 21210 31220 31321 21321
a[1] = a[temp];
}
for (int x: a){
System.out.print(++x);
}
}
}
What is the output of the following Java program?
class T2 {
public static void main(String[] args) {
int i;
boolean[] booleans = new boolean[10/2];
for (i = 0; i < booleans.length; i++) {
359 5 A 0.5 false,5 true,5 false,6 true,6
if (i % 2 == 0) {
booleans[i] = (i > 3);
}
}
System.out.print(booleans[i - 3]+","+i);
}
}
Which of the following syntaxes are valid for 1D array.
1.
int[ ] arr = new int [ 'J'];
2.
byte b = 10;
360 5 int[ ] a = new int [b]; C 0.5 Only 4 Only 1 1,2 & 3 Only 1 & 2
3.
short s = 10;
int[ ] a = new int [s];
4.
int[ ] a = new int [10.5];
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following Java program?
class T2 {
public static void main(String args[]) {
int a[] = new int [6];
int i = 3;
a[0] = 5; a[1] = 4; a[2] = 2; a[3] = 7;
for (int j=0;j<a.length;j++){
361 5 C 0.5 0 4 3 5
if (++j<=0){
a[i] = i++;
}
else{
a[i] = i--; } }
System.out.println(a[3]);
}}
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What are the contents of arr after the following code has been executed?
int[][] arr = { {3,2,1},{1,2,3}};
int value = 0;
for (int row = 1; row < arr.length; row++) {
for (int col = 1; col < arr[0].length; col++) {
if (arr[row][col] % 2 == 1)
{
372 5 arr[row][col] = arr[row][col] + 1; C 1 { {6, 4, 2}, {2, 4, 6}} { {3, 2, 1}, {1, 4, 6}} { {3, 2, 1}, {1, 4, 8}} { {4, 4, 2}, {2, 4, 4}}
}
if (arr[row][col] % 2 == 0)
{
arr[row][col] = arr[row][col] * 2;
}
}
}
Which of the following statements assigns the letter S to the third row and first
column of a two-dimensional array named strGrid (assuming row-major order).
A. strGrid[0][2] = "S";
373 5 B. strGrid[1][3] = "S"; A 1 D B C A
C. strGrid[3][1] = "S";
D. strGrid[2][0] = "S";
E. strGrid[0][0] = "S";
How would you get the value 6 out of the following array ?
int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};
A. a[0][3]
374 5 B. a[1][3] C 1 A D C B
C. a[0][2]
D. a[2][0]
E. a[3][1]
Given the following code segment, what is the value of sum after this code
executes?
int[][] matrix = { {1,1,2,2},{1,2,2,4},{1,2,3,4},{1,4,1,2}};
int sum = 0;
375 5 A 1 8 9 12 10
int col = matrix[0].length - 2;
for (int row = 0; row < 4; row++)
{
sum = sum + matrix[row][col];
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What are the contents of mat after the following code segment has been executed?
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
class Test{
public static void main(String srg[])
{
int a[][] = {{'a',97,'b',98,'c',99}};
for(int b[] : a) {
385 5 D 0.5 ‘a’97’b’98’c’99 979899979899 97979898999 Some Other Output
for(int c: b) {
System.out.print(c);
}
}
}
}
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output ?
class MCQ15{
public static void main(String args[])
{
int[]matrix[] = { {3,4,5},{10,2,20,4},{11,44,11,22}};
int mul = 1;
int col = matrix[0].length - 2;
388 5 C 0.5 49 60 51 55
for (int row = 0; row < 3; row++)
{
mul = mul + matrix[row][col];
}
System.out.print(mul);
}
}
Select correct one from the options for following 2D array declarations.
class ArrayDeclared{
public static void main(String [ ] args) {
int[ ][ ] x = new int[2][2]; //Line 1
. Line 1 is valid . Line 1 & 2 are valid Line 1,2 & 3 are valid
int [ ][ ]y = new int[2][2]; //Line 2 . All lines are valid
389 5 D 0.5 declaration, other Lines declarations, other Lines declarations, other
int z[ ][ ] = new int[2][2]; //Line 3 declarations.
are invalid are invalid. Lines are invalid.
int[ ] [ ]a = new int[2][2]; //Line 4
int[ ] b[ ] = new int[2][2]; //Line 5
int [ ]c[ ] = new int[2][2]; //Line 6
}}
What is the output of the Java code snippet?
class Arr1
{
public static void main(String args[])
{
int[][] a = { {10,11,12},{20,21,22},{1,2,3}};
int mul = 1;
390 5 int j = a[1].length; A 0.5 Run time error Compile time error 722 241
for (int i = 0; i < 4; i++)
{
mul = mul * a[i][j]-1;
}
System.out.print(mul);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the Java code snippet?
class Test
{
public static void main(String args[])
{
int[][] m = { {11,12,13,14},{21,22,23,24},{20,20,20,20},{2,4,6,8}};
int sum = 0;
391 5 B 0.5 56 33 29 13
for (int i = 0; i < 3; i++)
{
sum = sum + m[i++][2];
}
System.out.print(sum);
}
}
What are the contents of arr after the following code has been executed?
class T2 {
public static void main(String[] args) {
int a[][] = new int [][]{{1,2},{0,1},{0,0}};
a[2][1] += a[1][0];
int i,j;
393 5 A 0.5 313 302 310 212
i = a[2][1]++;
j = a[++i][i++];
System.out.print(a.length);
System.out.print(a[2][1]);
System.out.print(i+j);
}
}
394 5 What is the output of the following Java program? C 0.5 Ae178 1696599 169Ad 170Ac
Which of the following are not valid syntax(es) for array declaration
1. int[ ][ ] a,b;
395 5 2. int[ ] [ ]a,b; B 0.5 1 and 2 Only 4 Only 1 1, 2 and 3
3. int [ ]a[ ],b;
4. int [ ]a,[ ]b;
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
class MCQ{
public static void main (String agrs[ ]) {
int[ ] foreach[ ]=new int[3][0];
396 5 for (int each[ ]:foreach) D 1 000 111 compile time error Blank Output
for (int loop:each)
System.out.print(++loop);
}}
TOPIC NAME:- TWO DIMENSIONAL ARRAY (PROGRAMS)
397 5 Write a JAVA program to enter elements in a 2×2 array and print the same. 3
Write a program to read two 5*5 matrices from the user and store the addition of
two matrices in the resultant Matrix. i.e C=A+B , where A,B,C each one is 5*5
398 5 matrix. OR A and B are two n X n matrices.Write a JAVA program to read both A 5
and B matrices, add them and print the resultant C matrix. The maximum value n
may be taken as 9.
Write a program to read two matrix from the user and store the multiplication of
399 5 5
two matrix in the resultant matrix. i.e. C=A * B
400 5 Write a Program to find maximum element from 3*3 Matrices 4
401 5 Write a program to find the minimum value from the array of 3 x 3 4
402 5 Write a program to display transpose of given 3*3 matrix. 4
Write a program to count number of positive, negative and zero elements from 3 x
403 5 3
3 matrix.
Write a java program to display Transpose of a M×N matrix.
Take all required inputs of matrix and elements of matrix using Scanner class.
As example,
If Input Matrix is
1 2 3
404 5 3
4 5 6
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of the following code ?
class MCQ10{
public static void main(String args[]){
int a[][] = new int[3][];
a[0] = new int[4];
a[1] = new int[2];
405 5 a[2] = new int[3]; C 0.5 3 9 4 7
int j=0;
for(int i = 0; i<a.length;i++){
for(j = 0;j<a[i].length;j++)
{
j++;
}}
System.out.println(j);}}
UNIT 6 - STRINGS
TOPIC NAME:- String class and its methods (charAt(), length(), concat(), equals(), equalsIgnoreCase(), compareTo(), compareToIgnoreCase(), toUpperCase(),
toLowerCase(), split(), replace(), toString(), startsWith(), endsWith(), indexOf(), toCharArray(), trim() (MCQS)
Give Output
class Q207
{
public static void main(String[] args)
{
407 6 int i1 = 5; B 1 18 117 567 None of the above
int i2 = 6;
String s1 = "7";
System.out.println(i1 + i2 + s1);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of the following program?
class Test{
public static void main(String args[])
{
char ch[] = {'J','a','v','a'};
String s1 = "Java";
String s2 = new String ();
true false true
408 6 for (int i=0;i<ch.length;i++) B 1 Error
false true true
{
s2 = s2+ch[i];
}
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
}
}
What will be the output of the following program?
class Test{
public static void main(String args[])
{
String s1 = new String();
String s2 = new String();
409 6 B 1 HelloWorld Hello Hello World Error
s1 = "Hello";
s2 = "World";
s1.concat(s2);
System.out.println(s1);
}
}
What will be the output of the following program?
class Test
{
public static void main(String args[])
this
{ this
this is
String sentence = "this is a simple sentence"; is
410 6 A 1 is a Error
int a = 3; a
a simple sentence simple
String[] words = sentence.split(" ", a); simple sentence
sentence
for(int i = 0; i <= words.length - 1; i++)
System.out.println(words[i]);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of the following program?
class Test
{
public static void main(String args[])
{
String s = null;
An exception is thrown
411 6 if (s.length() == 0) D 1 1 2 3
at run time.
{ System.out.print("1"); }
else if (s == null)
{ System.out.print("2"); }
else
{ System.out.print("3"); }
}}
What will be the output of the following program?
class Test
{
public static void main(String args[])
{
String s1 = "Exam";
412 6 String s2 = new String(); D 1 0 1 32 Error
s2 = "ExaM";
s2.concate("Clear");
s2.replace("ExaM","Exam");
System.out.println(s1.compareTo(s2));
}
}
What will be the output of the following program?
class Test
{
public static void main(String args[])
{
String s1 = "World"; WorlD Clear World Clear World Clear WorlD Clear
413 6 A 1
String s2 = new String(); 0 0 32 32
s2 = "WorlD";
System.out.println(s2.concat(" Clear"));
System.out.println(s1.compareToIgnoreCase(s2));
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of the following program?
class Test {
public static void main(String args[]) {
String s1 = "hello";
String s2 = new String("hello");
String s3 = "hello";
if (s1 == s2) {
s1 and s2 equal s1 and s2 equal s1 and s2 not equal s1 and s2 not equal
414 6 System.out.println("s1 and s2 equal"); C 1
s1 and s3 equal s1 and s3 not equal s1 and s3 equal s1 and s3 not equal
} else {
System.out.println("s1 and s2 not equal"); }
if (s1 == s3) {
System.out.println("s1 and s3 equal");
} else {
System.out.println("s1 and s3 not equal"); }
}}
The output of the following code is?
class Test{
public static void main(String args[])
{
415 6 String s1 = new String ("madam"); B 1 madam Madam Compile time error Run time error
String s2 = new String ("Madam");
System.out.println(s1 = s2);
}
}
What will be the output of the following program?
class Test{
public static void main(String args[])
{
Throws an exception as
String s1 = new String();
416 6 B 1 string and int are not Hello10 10Hello Compilation error
s1 = "Hello";
compatible for addition
int x = 10;
System.out.println(s1 += x);
}
}
String s1 = "This is the KISMIS".replace("is","IS"); The first occurance of "is" All "IS" are replaced by All "is" are replaced by
417 6 C 1 Error message
In the above statement, the effect on given string is, is replaced by "IS". "is". "IS".
The output of the following program is?
class Test {
public static void main(String args[]) {
Convert "Z" to int 90 and
418 6 String s = "Java String Quiz"; C 1 Prints "z" Runtime Exception Prints "Z"
prints "90"
System.out.println(s.charAt(s.toUpperCase().length()));
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
The output of the following program is?
class Test {
public static void main(String args[]) {
String s1 = "abc";
419 6 String s2 = new String(); B 1 true -3 0 false
s2 = "def";
System.out.println(s1.compareTo(s2));
}
}
What will be the output of following code?
class MCQ22 {
public static void main(String args[]) {
String s1 = "LJ";
String s2 = new String();
s2 = "lJ";
420 6 if (s1.compareTo(s2) != 0) { B 1 Both strings are not equal Both strings are equal Compile time error None of these
System.out.println("Both strings are equal");
} else {
System.out.println("Both strings are not equal");
}
}
}
What will be the output of following code?
class MCQ20 {
public static void main(String args[]) {
char c[] = {'h', 'i', 'j', 'a', 'v', 'a', 'i', 's', 'b', 'a', 'c', 'k'};
String s = "hijavaisback";
String s1 = new String(c);
if (s1 == s) {
421 6 D 1 HiHi HiJavaisbackHi hiisbackHi hijavaisbackHi
s = s1 + "BYE";
} else {
s = s + "Hi";
}
System.out.println(s);
}
}
What will be the output of following code?
class MCQ21 {
public static void main(String args[]) {
String s[] = {"\0"}; if(s.length()==1){
System.out.print("1"); }
422 6 else if(s.length()==0){ System.out.print("0"); D 1 0 1 2 Compile time error
}
else if(s.length()==2){
System.out.print("2"); }
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class Trial {
public static void main(String[] args) {
String m = new String("ABC");
String n = new String("ABC");
String o = "ABC";
423 6 B 1 falsetruetrue falsefalsetrue truefalsefalse truetruefalse
String p = o;
System.out.print(m == n);
System.out.print(m == o);
System.out.print(o == p);
}
}
What will be the output of following code?
class Test {
public static void main(String[] args) {
byte b[] = {88, 89, 90};
424 6 C 1 888990 "888990" XYZ xyz
String s = new String(b);
System.out.println(s);
}
}
What will be the output of following code?
class concat1 {
public static void main(String[] x) {
String x = "abc";
425 6 String y = "abc"; D 1 abcabc abc null Error
x.concat(y);
System.out.print(x);
}
}
What will be the output of following code?
class Test
{
426 6 public static void main(String args[]) { A 1 115110 11511 1105110 Error
String s = new String("5");
System.out.println(1 + 10 + s + 1 + 10); }
}
What will be the output of following code?
class T2 {
public static void main(String args[]) {
char ch[] = {70, 71, 72, 102, 103, 104};
String s = new String(ch);
if (s.charAt(2) == 'H') {
427 6 s.toUpperCase(); C 1 fghfgh ch FGHfgh Compile time error
} else {
s.toLowerCase();
}
System.out.println(s);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following Java code snippet?
class MCQ{
public static void main (String agrs[ ]) {
428 6 B 1 Runtime Error Compile Error 0 1
String[] balls = { "\n" };
System.out.print(balls.length());
}}
TOPIC NAME:- StringBuffer class and its methods (append(), insert(), replace(), delete(), reverse(),capacity()), Difference between String and StringBuffer class
(MCQS)
What will be the output of the following program?
class Author {
public static void main(String[] s1) {
String name = "Human Jack";
Human Jack Human Jack
429 6 StringBuffer copy = new StringBuffer(name); A 1 Compilation Error Runtime Error
Human Jack (EMPTY)
System.out.println(name);
System.out.println(copy);
}
}
What will be the output of the following program?
class StringTest {
public static void main(String arg[]) {
String input = "121ExAmQueStIOns421";
int a = 6;
int b = 3;
int c = a & b;
2 2 3
430 6 System.out.println(c); D 1 Compilation Error
121examquestions421 121EXAMQUESTIONS421 121ExAmQUESTIONS421
StringBuffer sb = new StringBuffer(input);
if (input.equalsIgnoreCase("ExA") || input.equalsIgnoreCase(sb)) {
System.out.print(input.toUpperCase());
} else {
System.out.print(input.toLowerCase());
}
}}
What will be the output of the following program?
class Subject {
public static void main(String[] sb) {
String name = "JAVA Programming";
JAVA Programming JAVA
431 6 StringBuffer sb = new StringBuffer(name); D 1 JAVA Programming Error
Learning ProgrammingLearning
sb.append("Learning");
System.out.println(sb);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of the following program?
class Test {
public static void main(String[] args) {
StringBuffer stringBuffer1 = new StringBuffer(10);
StringBuffer stringBuffer2 = new StringBuffer("JAVA TEST");
432 6 StringBuffer stringBuffer3 = new StringBuffer(1); B 1 #JAVA Test #JAVA TEST## #JAVA TEST##J #JAVA TEST## J
StringBuffer stringBuffer4 = new StringBuffer('J');
System.out.println(stringBuffer1 + "#" + stringBuffer2 + "#" + stringBuffer3 +
"#" + stringBuffer4);
}
}
What will be the output of the following program?
class Test {
public static void main(String[] args) {
StringBuffer stringBuffer1 = new StringBuffer(10+2);
StringBuffer stringBuffer2 = new StringBuffer("JAVA Test");
12-tseT AVAJ-24- 12-tseT AVAJ-34-
433 6 StringBuffer stringBuffer3 = new StringBuffer("Learning"); B 1 12-tseT AVAJ-24-CoOmpile Error
Coompile COompile
StringBuffer stringBuffer4 = new StringBuffer("Compile");
System.out.println(stringBuffer1.capacity() + "-" + stringBuffer2.reverse() + "-" +
stringBuffer3.capacity() + "-" + stringBuffer4.insert(1,'O'));
}
}
What will be the output of the following program?
class Test {
public static void main(String[] args) {
String s = "RUN";
StringBuffer stringBuffer1 = new StringBuffer();
stringBuffer1.insert(0,"Hello");
StringBuffer stringBuffer2 = new StringBuffer("JAVA Test");
434 6 C 1 21-25-24-19 16-25-42-19 16-25-36-19 34-25-36-19
StringBuffer stringBuffer3 = new StringBuffer("J");
stringBuffer3.append("This is JAVA Programming.");
StringBuffer stringBuffer4 = new StringBuffer(s);
System.out.println(stringBuffer1.capacity() + "-" + stringBuffer2.capacity() + "-"
+ stringBuffer3.capacity() + "-" + stringBuffer4.capacity());
}
}
What will be the output of the following program?
class Test1 {
public static void main(String[] args) {
StringBuffer data;
Thomas Alva Edison Thomas Alva Edison Thomas Alva Edison
String inventor = "Thomas Alva Edison";
Capacity 16. Capacity 0. Capacity 16.
435 6 data = new StringBuffer(); D 1 Error
Thomas Alva Edison Thomas Alva Edison Thomas Alva Edison
System.out.println(inventor + " Capacity " + data.length + ".");
Capacity 18. Capacity 18. Capacity 34.
data = new StringBuffer(inventor);
System.out.println(inventor + " Capacity " + data.length + ".");
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of the following program?
class Test {
public static void main(String[] a1) {
StringBuffer givenString = new StringBuffer("Now you need to SOLVE this
Question. Thank you.");
int count = 0; Found 6 o's in the
Found 6 o's in the Found 5 o's in the
for (int i = 0; i < givenString.length(); i++) { givenString.
givenString. givenString.
436 6 if (givenString.charAt(i) == 'O' || givenString.charAt(i) == 'o') { D 1 Now you need to SOLVE Error
N_w y_u need t_ S_LVE N_w y_u need t_ SOLVE
count++; this Question. Thank
this Questi_n. Thank y_u. this Questi_n. Thank y_u.
givenString.replace(i, '_'); you.
}
}
System.out.println("Found " + count + " o's in the givenString.");
System.out.println(givenString);
}}
What will be the output of the following program?
class Test {
public static void main(String[] args) {
StringBuffer givenString = new StringBuffer("Now you need to SOLVE this
Question. Thank you.");
int count = 0;
for (int i = 0; i < givenString.length(); i++) {
437 6 if (givenString.charAt(i) == 'e' || givenString.charAt(i) == 'E') { A 1 1 2 3 4
count++;
givenString.delete(0,givenString.length());
givenString.append("Solved");
}
}
System.out.println(count);
}}
What will be the output of the following program?
class StringBuffer {
public static void main(String args[]) {
String s = "JAVA Exam";
StringBuffer sb = new StringBuffer(s);
438 6 D 1 JAVA Programming JAVA ProgrammingE JAVA EProgramming Error
sb.insert(5,"Programming");
sb.delete(16,20);
System.out.println("Updated String is: "+sb);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of the following program?
class Test {
public static void main(String args[]) {
StringBuffer sb1 = new StringBuffer("float: ");
float c = 1.25f;
sb1.append(c);
float: 1.25f float: 1.25f float: 1.25 float: 1.25
439 6 sb1.append("\n"); C 1
object: Test object: TesT object: TesT object: Test
sb1.append("object: ");
String obj = new String("TesT");
sb1.append(obj);
System.out.println(sb1);
}
}
What will be the output of following program?
class Test
{
public static void main(String args[])
{
440 6 C 1 This Example This mple This ample This xample
StringBuffer sb = new StringBuffer("This is Example");
sb.delete(5,10);
System.out.println(sb);
}
}
The output of the following program is?
class Test {
public static void main(string args[]) {
StringBuffer sb = new StringBuffer();
441 6 sb.append("I have two pets"); D 1 I have two dogs I have twodogs I have two pets Error message
sb.replace(11, 15, "dogs");
System.out.print(sb);
}
}
What will be the output of following code?
class MCQ19 {
public static void main(String args[]) {
StringBuffer sb1 = new StringBuffer("Hi Java Exam");
442 6 C 1 Hi Exam Exam Hi Exam Hi Hi ExamHi Exam Hi Exam Java
StringBuffer sb2 = new StringBuffer(sb1.delete(3, 7));
System.out.println(sb1.toString() + sb2.toString());
}
}
What will be the output of following code?
class MCQ17 {
public static void main(String args[]) {
String s = "";
443 6 StringBuffer sb = new StringBuffer(s); C 1 16 34 60 68
sb.append("Hello LJ How are You? This is Java T2 Exam and All the Best.");
System.out.println(sb.capacity());
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class Trial {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("ABC");
444 6 B 1 32 35 56 50
StringBuffer sd = new StringBuffer();
System.out.print(sb.capacity() + sd.capacity());
}
}
What will be the output of following code?
class Trial {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("ABC");
445 6 D 1 ABCXYZ AXBYCZ 656667 Compile time error
StringBuffer sd = new StringBuffer("XYZ");
System.out.print(sb + sd);
}
}
What will be the output of following code?
class Trial {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("ABC");
446 6 B 1 ABAB ABCABC 65666567 Compilation error
StringBuffer sd = new StringBuffer("ABC");
System.out.print(sb.toString() + sd.toString());
}
}
What will be the output of following code?
class Bulb {
public static void main(String[] args) {
StringBuffer data;
String inventor = "Thomas Alva Edison";
data = new StringBuffer("/n");
447 6 System.out.print(data.capacity()); A 1 183432 183424 161632 181624
data = new StringBuffer(inventor);
System.out.print(data.capacity());
data = new StringBuffer("append(inventor)");
System.out.print(data.capacity());
}
}
What will be the output of following code?
class TheFinale {
public static void main(String[] args) {
StringBuffer input = new StringBuffer("Will Argentina win?");
String input1 = input.toString();
input1.replace('o', 'e');
448 6 B 1 Will Argenti win?Yes Will Argen win?Yes Will Argentina win?Yes Wil Argen win?Yes
input1 = input1.replace("Will", "Yess");
input.delete(10, 14);
input.append("Yes");
System.out.println(input);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class Methods {
public static void main(String args[]) {
StringBuffer c = new StringBuffer("HARDIK");
c.insert(1, "ER-");
449 6 StringBuffer c1 = new StringBuffer(" PARTH"); C 1 HTRAP KIDRAH-RE HTRAP KIDRAREH HTRAP KIDRA-REH Error
c.append(c1);
StringBuffer s2 = c.reverse();
System.out.println(s2);
}
}
What will be the output of following code?
class CompareToIgnoreCase {
public static void main(String args[]) {
StringBuffer c = new StringBuffer("HARDIK");
450 6 StringBuffer c1 = new StringBuffer("PARTH"); C 1 PARTHfalse PARTHtrue PARTH0 HARDIKfalse
c1.append(c1.compareTo(c) + c.compareTo(c1));
System.out.println(c1);
}
}
What will be the output of following code?
class ReplaceMethod {
public static void main(String[] args) {
StringBuffer s = new StringBuffer("Java");
451 6 System.out.print(s); D 1 Java Programming Programming Javaramming JavaProgramming
s.replace(0, 4, "Programming");
System.out.print(s);
}
}
What will be the output of following code?
class StringBufferClass {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("Java is ON ");
452 6 System.out.print(sb.charAt(5) + 1); A 1 10698 10597 Java Error
sb = new StringBuffer("Java");
System.out.print(sb.charAt(3) + 1);
}
}
What will be the output of following code?
class String1 {
public static void main(String args[]) {
StringBuffer sb1 = new StringBuffer("Infosense");
StringBuffer sb2 = new StringBuffer("Infosense");
453 6 String ss1 = "Solution"; D 1 falsetruetrue falsefalsetrue truefalsefalse falsefalsefalse
System.out.print(sb1 == sb2);
System.out.print(sb1.equals(sb2));
System.out.print(sb1.equals(ss1));
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class Test {
public static void main(String[] args) {
454 6 StringBuffer sb = new StringBuffer(); sb.append(2.3); A 1 2.3afalse 2.397false 2.3a 2.397
sb.append('a');
sb.append(false); System.out.println(sb);
}}
What will be the output of following code?
class output
{
public static void main(String args[]) {
455 6 C 1 HelloWorld worldHello WorldHello Error
String c = "Hello";
StringBuffer c1 = new StringBuffer("World"); c1.append(c);
System.out.println(c1);
}}
What will be the output of following code?
class Test {
public static void main(String args[]) {
StringBuffer sb1 = new StringBuffer();
sb1.append("c");
456 6 sb1.append("object:"); C 1 c coobject: cobject:TesT TesT
String obj = new String("TesT");
sb1.append(obj);
System.out.print(sb1);
}
}
What will be the output of following code?
class Test {
public static void main(String args[]) {
StringBuffer sb = new StringBuffer("JAVA IS MY FAVOURITE LANGUAGE");
457 6 D 1 JAVA JAVA I No Output Error
sb.delete(5);
System.out.println(sb);
}
}
What will be the output of following code?
class Test {
public static void main(String args[]) {
StringBuffer s=new StringBuffer("Hello");
458 6 B 1 H o 1 e
s.delete(0,s.length( )-1);
System.out.println(s);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class Test {
public static void main(String args[]) {
String s = "Lj UniVersity2022";
StringBuffer sb = new StringBuffer(s);
if (s.equalsIgnoreCase("Uni") || s.equalsIgnoreCase("20")) {
459 6 A 1 Lj ersity2022 2202ytisreVinU jL Lj UniVersity2022 Error
System.out.print(sb.reverse());
} else {
System.out.print(sb.delete(3, 7));
}
}
}
What will be the output of following code?
class Test {
public static void main(String args[]) {
String s1 = "JAVA Programming";
String s2 = "Best Programming"; 8 Best falseJAVA 8JAVA
460 6 C 1 Error
StringBuffer sb = new StringBuffer(s1); Programmingstudent Programmingstudent Programmingstudent
System.out.print(s1.compareTo(s2));
System.out.print(sb.append("student"));
}
}
What will be the output of following code?
class Test {
public static void main(String args[]) {
StringBuffer s = new StringBuffer("HELLO Friends");
int count = 0;
for (int i = 0; i < s.length(); count++) {
461 6 System.out.println(i); D 1 2 1 0 Infinite Loop
if (s.charAt(i) == 'e' || s.charAt(i) == 'E')
++i;
}
System.out.println(count);
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class Test {
public static void main(String args[]) {
StringBuffer s1 = new StringBuffer("GOod MORning");
int t = 0;
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) == 'O' || s1.charAt(i) == 'o') {
462 6 B 1 GO_MORning GO_Rning GO_Orning Error
t++;
s1.replace(2, 5, "_");
}
}
System.out.println(s1);
}
}
What will be the output of following code
class Test
{
public static void main(String args[]) {
StringBuffer sb="LJ";
463 6 D 1 LJ LJBest LJUNIVERSITY Compile time error
StringBuffer sb1 = new StringBuffer("UNIVERSITY"); sb.append("Best");
System.out.print(sb);
System.out.print(sb1);
}}
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class T2 {
public static void main(String args[]) {
String s1 = "Test 2";
s1 = s1 + 'T';
466 6 StringBuffer sb1 = new StringBuffer(s1); B 1 Test7 2T Test62T TestT 72 TestT 62
sb1.delete(4, 5);
sb1.insert(4, sb1.length());
System.out.println(sb1);
}
}
What will be the output of following code?
class T2 {
public static void main(String args[]) {
StringBuffer Trial;
String run = "Testing StringBuffer";
10 Testing 16 Testing
467 6 Trial = new StringBuffer(10); A 1 10 run2022 16 run2032
StringBuffer2022 StringBuffer2032
System.out.print(Trial.capacity() + " ");
System.out.print(Trial.append(run + 20));
System.out.print(Trial.capacity());
}
}
What will be the output of following code?
class T2 {
public static void main(String args[]) {
String s1 = "Java Exam";
StringBuffer s2 = "Java exam";
468 6 D 1 true,true false,false true,false Error
s2.toString();
System.out.print(s1.equals(s2) + ",");
System.out.print(s1.equalsIgnoreCase(s2));
}
}
What will be the output of following code?
class T2 {
public static void main(String args[]) {
String s1 = "Learning Programming";
String s2 = new String();
s2 = "Learning Programming";
s1.toLowerCase();
469 6 s2.toUpperCase(); B 1 0 -2 -32 2
s1.equals(s2);
StringBuffer sb1 = new StringBuffer(s2);
sb1.delete(18, 20);
sb1.insert(18, "ngss");
s2 = sb1.toString();
System.out.print(s1.compareTo(s2));
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class T2 {
public static void main(String args[]) {
char ch[] = {'E', 'x', 'a', 'M'};
char ch1 = 0;
String s1 = new String(ch);
for (int i = 0; i < s1.length(); i++) {
470 6 if (i % 3 == 0) { C 1 x ExaM xMax M MExxE x Mexx
ch1 = s1.charAt(i);}}
System.out.print(ch1 + " ");
StringBuffer sb = new StringBuffer(s1);
sb.reverse();
sb.replace(1, 2, "Ex");
sb.delete(3, 3);
System.out.println(sb);}}
What will be the output of following code?
class T2 {
public static void main(String args[]) {
String s1 = new String("Java Program");
s1.concat(" Run");
System.out.print(s1.compareToIgnoreCase("Java Program"));
String[] arr = s1.split("a", 3);
471 6 String new_string = ""; A 1 0J0V1JvJ 4j0v1jv0J 0J0v1JVJ 0J0V1Jv
for (int i = 0; i < arr.length; i++) {
if (arr[i].length() == 1) {
System.out.print(arr[i].toUpperCase() + i);
new_string += arr[i];}}
StringBuffer sb1 = new StringBuffer(new_string);
sb1.append(s1.charAt(4));
System.out.print(new_string + sb1.delete(1, 5));}}
What will be the output of following code?
class mcq {
public static void main(String[] arg) {
StringBuffer sb1 = new StringBuffer(4);
sb1.append("Hello");
472 6 C 1 10,22 5,10 10,10 16,16
System.out.print(sb1.capacity() + ",");
sb1.append("Hello");
System.out.println(sb1.capacity());
}
}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What will be the output of following code?
class String1 {
public static void main(String[] arg) {
StringBuffer sb1 = new StringBuffer("Hello");
StringBuffer sb2 = new StringBuffer("Hello");
String s1 = new String("Hello");
473 6 String s2 = new String("Hello"); B 1 falsetruetruetrue falsefalsefalsetrue falsefalsetruetrue falsetruefalsetrue
System.out.print(sb1.equals(sb2));
System.out.print(s1 == s2);
System.out.print(sb1 == sb2);
System.out.print(s1.equals(s2));
}
}
What will be the output of following code?
class s1 {
public static void main(String[] arg) {
String s = new String("Hello");
s.concat("Hii");
474 6 StringBuffer sb = new StringBuffer("Hello"); A 1 HelloHelloHii HelloHello HelloHiiHelloHii Compile time Error
sb.append("Hii");
System.out.print(s);
System.out.print(sb);
}
}
What will be the output of following code?
class sss1 {
public static void main(String[] arg) {
StringBuffer sb = "ljiet";
475 6 sb.append("Hii"); D 1 ljietHii Hiiljiet etHii Compile time error
sb.delete(0, 2);
System.out.print(sb);
}
}
What is the output of the following Java code snippet?
class MCQ{
public static void main (String agrs[ ]) {
StringBuffer sb1 = new StringBuffer(4);
476 6 sb1.append("Hello World"); A 1 11,24 22,24 22,22 None of given
System.out.print(sb1.capacity() + ",");
sb1.append("Hello World");
System.out.println(sb1.capacity());
}}
L.J Institute of Engineering and Technology, Ahmedabad
Computer Programming Using JAVA-I Practice Book (SEM-I-2024 CE related Branches)
Note : This practice book is only for reference purpose. LJU Test question paper may not be completely set from this practice book
Unit
Sr No Question_Text MCQ Answer Marks Option A Option B Option C Option D
Number
What is the output of the following Java code snippet?
class MCQ{
public static void main (String agrs[ ]) {
String sb="INDIA";
StringBuffer s=new StringBuffer(sb);
477 6 A 1 AIDNANADNI IANAIA AINDANANDI Compile Error
s.delete(0,s.charAt(2)-68);
s.insert(3,"ANAND");
s.toString().replace("ND","");
System.out.print(s.reverse());
}}