Name the basic primitive data types in java.
Atleast 5
int, float, double, boolean, char
Write the import statement that imports the scanner class to your program.
import java.util.Scanner;
What is the keyword you use to check for an alternate condition in case the 'if' condition fails?
else if
What is the function you use to take input from the user?
input()
while True :
print("HI")
"Hi" is printed infinite times
What class do you import to take input from the user?
Scanner
What method do you write to take input for String data type?
next() or nextLine()
What is the logic you write to check if n is an even number?
n%2==0
What is the default data type of the value that input() takes?
String
What does the code do?
n = 6
c=0
while c<=n:
print(c)
c+=1
0 1 2 3 4 5 6
What are the different types of statements written to display output?
print, println, printf
If an input variable holds a value 3.62 then what is it's data type?
float or double
What is/are the keyword/s used for conditional statements other than if-else ladder?
switch and case
What is the output?
x = 82
y = 26
print("x+y")
x+y
What does this print in python?
for i in range(1,10):
print(2*i)
prints first 10 multiples of 2
What is the return type of main method in java?
void
If you have to check if a variable s is holding the string "Happy Halloween", how do you write the condition?
if(s.equals("Happy Halloween")) or
if(s.equalsIgnoreCase("happy halloween"))
s = "Hello World!"
print(s[1:5])
ello
for i in range(1,5):
for j in range(1,5):
if i==j:
print(i*j)
1 4 9 16 25
What words in the main method takes input from command line?
String[] args
printf() makes use of identifiers for variables. What will be the identifier for a variable of data type int?
%d
int a = 5;
int b = 10;
int c = 15;
if (a > 0) {
if (b < 5) {
System.out.println("First");
} else if (c == 15) {
System.out.println("Second");
} else {
System.out.println("Third");
}
} else {
System.out.println("Fourth");
}
Second
What does s[::-1] do to the string s?
Reverses the string
x = 3
y = 0
while x < 15:
x = x * 2
y = y + x
print(x,y)
24 42