0% found this document useful (0 votes)
6 views4 pages

Java Console Output Questions

The document contains sample programming questions related to Java, focusing on console output from various code snippets and logical expressions. It includes tasks to determine printed values from given code segments and requires completion of a program that identifies the longest of three input strings. The questions test understanding of operators, control flow, and string manipulation in Java.

Uploaded by

yysmisty12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Java Console Output Questions

The document contains sample programming questions related to Java, focusing on console output from various code snippets and logical expressions. It includes tasks to determine printed values from given code segments and requires completion of a program that identifies the longest of three input strings. The questions test understanding of operators, control flow, and string manipulation in Java.

Uploaded by

yysmisty12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sample Questions

1. Write the values that will be printed to the console by the statements below. If the
expression is incorrect, write “error”:

double a = 9.0, b = 2.0;


int i = 9, j = 2;
char c = ‘a’;

a. [Link](i % j);

b. [Link](i / j + a / b);

c. [Link](5 < i < 20);

d. [Link]( (char) (c + 5) );

e. [Link]( ((i == 9) || c == ‘b’) && (j >= 2));


2. Read the following programs, write the values that will be printed to the console:

Question a.

public class test1


{
public static void main(String[] args)
{
int a = 1;
int b = 2;
int c = 3;

if(a > 1)
{
if (b == 2 || c == 3)
{
[Link](a + b + c);
}
else
{
[Link](a - b - c);
}
}
else
{
if (b > 1 && c > 2)
{
[Link](a - b + c);
}
else
{
[Link](a + b - c);
}
}

}
}
Question b.

public class test2


{
public static void main(String[] args)
{
int i = 1;
int sum = 0;

while ( i < 10 )
{
i++;

if (i % 2 == 0)
{
sum = sum + i;
}
else
{
continue;
}
}
[Link](sum);
}
}
3. The following program reads three strings, and then prints out the longest one.
Complete the following program:

import [Link];

public class test2


{
public static void main(String[] args)
{
Scanner in = new Scanner([Link]);

int i;
String s1, s2, s3;

s1 = [Link]();
s2 = [Link]();
s3 = [Link]();

}
}

You might also like