Professional Documents
Culture Documents
An expression involving byte, int, and literal numbers is promoted to which of these
before any calculation is done?
(a) int (b) long (c) byte (d) float
2. 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
1
7. What is the output of this program?
class Modulus {
public static void main(String args[])
{
double a = 25.64;
int b = 25;
a = a % 10;
b = b % 10;
System.out.println(a + " " + b);
}
}
(a) (b) (c) 5 5 (d)
5.6400000000000 5.6400000000000 5
01 5 01 5.0 5.6400000000000
01
11 Which of these is used to perform all input & output operations in Java?
.
(a) streams (b) Variables (c) Classes (d) Methods
13 Which of these class is used to read characters and strings in Java from console?
.
(a) (b) StringReader (c) (d)
2
BufferedReader BufferedStreamReade InputStreamReade
r r
class dynamic_initialization
{
public static void main(String args[])
{
double a, b;
a = 3.0;
b = 4.0;
double c = Math.sqrt(a * a + b * b);
System.out.println(c);
}
}
3
20 What is the output of this program, Command line execution is done as –
“java Output This is a command Line”?
class Output
{
public static void main(String args[])
{
System.out.print("args");
}
}
(a)java (b) args (c) Output (d) This
21 What is the output of this program, Command line execution is done as – “java
Output command Line 10 A b 4 N”?
class Output
{
public static void main(String args[])
{
System.out.print((int)args[2] * 2);
}
}
(a) Java (b) 10 (c) 20 (d) b
4
25 What is the output of this program?
class mainclass {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
if (var2)
System.out.println(var1);
else
System.out.println(var2);
}
}
(a) 0 (b) 1 (c)true (d)false
5
{
char c1 = 'D';
char c2 = 84;
c2++;
c1++;
System.out.println(c1 + " " + c2);
}
}
(a) E U (b) U E (c) V E (d)U F
6
34 Which operator is used to invert all the digits in a binary representation of a number?
(a) ~ (b) <<< (c) >>> (d) ^
7
{
public static void main(String args[])
{
int x;
x = 10;
x = x >> 1;
System.out.println(x);
}
}
(a) 10 (b) 5 (c) 2 (d)20
8
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
(a) 1 (b) 2 (c) Runtime error (d) Unpredictable
owing to division by behavior of
zero in if condition program
9
int x = 8;
System.out.println(++x * 3 + " " + x);
}
}
24 8
24 9
27 8
27 9
(a) 24 8 (b) 24 9 (c) 27 8 (d) 27 9
10
50 public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Which statement is true?
(a) Compilation fails. (b) "odd" will (c) "even" will (d) "odd" will be
always be always be output for odd
output. output. values of x, and
"even" for even
values.
54 What would be the output of the following code snippet if variable a=10?
if(a<=0)
11
{
if(a==0)
{
System.out.println("1 ");
}
else
{
System.out.println("2 ");
}
}
System.out.println("3 ");
(a) 3 (b)1 2 (c) 2 3 (d) 1 3
57 Which of these is returned by “greater than”, “less than” and “equal to” operators?
a) Integers
b) Floating – point numbers
c) Boolean
d) None of the mentioned
(a) Integers (b) Floating (c) Boolean (d)None of the
point above
12
59 What is the output of this program?
class comma_operator
{
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
System.out.println(sum);
}
}
(a) 5 (b) 6 (c) 14 (d) Compilation
Error.
60 Which concept of Java is achieved by combining methods and attribute into a class?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction
(a)Encapsulation (b) Inheritance (c)Ploymorphis (d)Abstraction
m
Program
An Armstrong number is the one that equals the sum of its digits raised to the power of the
number of digits in that number which is to be checked.
Import java.io.*;
import java.util.*;
public class ArmstrongNumber {
public static boolean isArmstrong(int input) {
String inputAsString = input + "";
int numberOfDigits = inputAsString.length();
int copyOfInput = input;
int sum = 0;
while (copyOfInput != 0) {
int lastDigit = copyOfInput % 10;
sum = sum + (int) Math.pow(lastDigit, numberOfDigits);
copyOfInput = copyOfInput / 10;
13
}
if (sum == input) {
return true;
} else {
return false;
}
}
Sample Output
14