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

9-4 Code for Analysis

The document contains a series of Java programming questions, each asking for the output of specific code snippets. It covers various topics such as operators, data types, variable declarations, and control structures. Additionally, it includes questions about the range of char data types and boolean values in Java.

Uploaded by

duneshvasa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

9-4 Code for Analysis

The document contains a series of Java programming questions, each asking for the output of specific code snippets. It covers various topics such as operators, data types, variable declarations, and control structures. Additionally, it includes questions about the range of char data types and boolean values in Java.

Uploaded by

duneshvasa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1. What is the Output of the following program?

public class Operator


{
public static void main(String[] args)
{
int a=20, b=10;
if((a>b)&&(--b <12))
{
System.out.println(b); # 9

}
System.out.println(a); # 20
}
}

2. What is the output of the following code?


public class Operator {
{
public static void main(String args[])
{
double a = 1 + 9;
double b = a / 6;
int c = 1 + 9;
int d = c / 8;
System.out.print(b + " " + d); #1.666 1

}
}

3. What is the output of the following code?


public class Operator
{
public static void main(String args[])
{
double a = 892.457;
int b = 10;
a = a % 10;
b = b % 10;
System.out.println(a + " " + b); # 2.4569999999999936 0
}
}

4. What is the output of the following code


public class Operator
{
public static void main(String[] args)
{

int a = 21;
int b = a;
System.out.println(b); #21

b += a;
System.out.println(b); #42

a *= a;
System.out.println(a); #441
}
}

5. What is the output of the following program?


public class Operator
{
static int operate(int a,int b)
{
return (a * b);
}
static float operate(float a,float b)
{
return (a / b);
}
public static void main(String[] args) {
int x = 11, y = 23;
float n = 9, m = 4;
System.out.print(operate(x, y)+"\t");
System.out.println(operate(n, m)); # 253 2.25
}
}

6. What is the output of the following program?

int x = 0;

int y = 10;

do {

y--;

++x;

}
while (x < 5);

System.out.print(x + "," + y); #5,5

7. What is the output of the following program?


public static void main(String args[])
{
int roll;
System.out.println(roll);
}

8 Which of the following are valid variable declarations?

i. float = 10.5f;

ii. boolean isOn = "true"

iii. char gender = 'F';

iv. int value = 20;

9. What is the output of the following program?

public class Test {

public static void main(String[] args) {

int i = 0;

i = i++ + i;

System.out.println("I = "+i); #1
}

10. What is the output of the following program?

class Test {

public static void main(String[] args) {

int d, a = 2, b = 2;

d = a++ + ++b;

System.out.print(d+" "+a+" " +b); #5 3 3

11. What is the output of the following program?


class Test {

public static void main(String[] args) {

int a = 1, b = 1, c;

c = a++ + b;

System.out.println("a="+a+" b="+b+" c="+c); # a=2 b=1 c=2

12 . What is the numerical range of a char in Java?

a) -128 to 127

b) 0 to 256

c) 0 to 32767

d) 0 to 65535

13 . Which of these coding types is used for data type characters in Java?

a) ASCII

b) ISO-LATIN-1

c) UNICODE

d) None of the mentioned

14 Find the output of the following code.

int Integer = 24;

char String = ‘I’; #Error

System.out.print(Integer);

System.out.print(String);
15. Find the output of the following Program

class Test
{
public static void main(String [] args)
{
char ch = '\u0041';
System.out.println(ch); #A
}

16. Which of these values can a boolean variable contain?

a) true
b) false
c) 0
d) 1

17 Find the output of the following program.

public class Test


{
public static void main(String[] args)
{
byte x = 127;
x++;
x++;
x++;
System.out.print(x);
}
}

18 Find the output of the following program.


public class Test
{
static int i =5;
public static void main(String... args)
{
System.out.println(i++); #5
System.out.println(i); #6
System.out.println(++i); #7
System.out.println(++i+i++); #16
}
}

19. Find the output of the following program.


public class Test
{
public static void main(String[] args)
{

int i = 7;
int j = -9;
double x = 72.3;
double y = 0.34;

System.out.println("i is " + i);


System.out.println("j is " + j);
System.out.println("x is " + x);
System.out.println("y is " + y);

}
}
# i is 7
j is -9
x is 72.3
y is 0.34

20. Find the output of the following program.

public class Test


{
public static void main(String[] argv)
{
final int x = 5;
int y = x++; //error
}
}

You might also like