Day1
Day1
fundamentals
DAY 1 QUESTIONS
MCQ 1
Which of the following is a valid variable declaration in Java?
A) int 2x = 10;
B) float rate = 1.5;
C) char name = "A";
D) Boolean valid = "true";
MCQ 2
What is the default value of an int variable in Java ?
A) 0
B) null
C) undefined
D) 1
MCQ 3
What is the range of short data type in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
b) -32768 to 32767
c) -2147483648 to 2147483647
A) Prints 0
B) Prints null
C) Compile-time error
D) Runtime exception
MCQ 9
Which of the following statements is true about variable names in Java?
A) Variable names can start with a digit.
B) Variable names are case-insensitive.
C) Variable names cannot contain special characters except _ and $.
D) Java allows spaces in variable names.
MCQ 10
What is the result of this expression?
int a = 3, b = 2;
System.out.println(a / b);
A) 1.5
B) 1
C) 2
D) 0
Problem 1
Write a program that takes the length and width of a rectangle as input and calculates its area.
Sample output:
Enter length: 5.5
Enter width: 3.2
Area of rectangle: 17.6
Problem 2
Write a program that asks the user for his first name and last name and then switches them
Sample output
Enter first name: john
Enter last name: doe
The name is : doe john