0% found this document useful (0 votes)
4 views13 pages

Day1

The document contains a series of multiple-choice questions (MCQs) related to programming fundamentals in Java, covering topics such as variable declaration, data types, and variable initialization. Additionally, it includes two programming problems that require writing code to calculate the area of a rectangle and switch the first and last names of a user. The questions and problems are designed to test knowledge and practical skills in Java programming.

Uploaded by

mennaabozahow46
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)
4 views13 pages

Day1

The document contains a series of multiple-choice questions (MCQs) related to programming fundamentals in Java, covering topics such as variable declaration, data types, and variable initialization. Additionally, it includes two programming problems that require writing code to calculate the area of a rectangle and switch the first and last names of a user. The questions and problems are designed to test knowledge and practical skills in Java programming.

Uploaded by

mennaabozahow46
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
You are on page 1/ 13

Programming

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

d) None of the mentioned


MCQ 4
What is the range of byte data type in Java?
a) -128 to 127

b) -32768 to 32767

c) -2147483648 to 2147483647

d) None of the mentioned


MCQ 5
Which one is a valid declaration of a boolean?
a) boolean b1 = 1;
b) boolean b2 = ‘false’;
c) boolean b3 = false;
d) boolean b4 = ‘true’
MCQ 6
Which of these data types has the largest range of values in Java?
A) int
B) short
C) long
D) byte
MCQ 7
What happens if you try to use a local variable in Java without initializing it?
A) It gets a default value.
B) It causes a runtime error.
C) It causes a compile-time error.
D) It prints null.
MCQ 8
16. What will happen if you try to compile and run the following code?
int x;
System.out.println(x);

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy