0% found this document useful (0 votes)
246 views3 pages

Introduction To Java Worksheet 1

This document contains an introductory worksheet on Java basics with questions about class headers, variable declarations, the purpose of the main method, Java's program lifecycle, semicolon and curly bracket usage, arithmetic expressions, casting, and writing a full program to calculate the perimeter and area of a rectangle and the shaded area inside a square with an inscribed circle. The worksheet contains over 35 questions testing fundamental Java concepts.

Uploaded by

Dan Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views3 pages

Introduction To Java Worksheet 1

This document contains an introductory worksheet on Java basics with questions about class headers, variable declarations, the purpose of the main method, Java's program lifecycle, semicolon and curly bracket usage, arithmetic expressions, casting, and writing a full program to calculate the perimeter and area of a rectangle and the shaded area inside a square with an inscribed circle. The worksheet contains over 35 questions testing fundamental Java concepts.

Uploaded by

Dan Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: _______________________________________ Period: _____

Date:_________________

Introduction to Java Worksheet #1


Basics:
1. Write the entire class header for a class called Program.

2. Declare a variable of each primitive type and initialize each appropriately.


Variable can be named anything.

3. What is the purpose of the PSVM method header? Write the entire header.

4. Describe the life cycle of a program in Java, from what you write to the
execution by the computer.

5. When/how are semicolons and curly brackets used?

Display:
6. Write a single statement to display your age.

7. What is the difference between the methods print and println?

Mixed Mode Arithmetic: Identify the value of x, assuming the statements are
executed in Java and are separate from each other.
8. int x = 6*2+(3-5);

12.int a = 6/4;
double x = 3*a;

9. int a = 4;
int b = 3 a;
int x = a*b;

13.int a = 5.3;
double x = a;

10.double a = 13.4;
int b = 2;
double x = 2*a/b;

14.int a = 76%14;
int b = 13 (12*a);
double x = b;

11.double a = 13.4;
int b = 2;
int x = 2*a/b;

15.int a = 5*(2.4/1.2);
16.double x = 6

17.Casting: Identify the value of x, assuming the statements are executed in


Java and are separate from each other.
18.int x = (int)4.5/2 + (int)(6.3/9.0);
19.
20.double average = (5.0 + 2.1 + 3.8 + 3.9)/4;
21.int x = (int)(average + 13);

22.
23.int x = (double)(3.8-4);
24.
25.double x = (int)(7.2/3.5);
26.
27.double x = (int)5.2*12 + 1;
28.
29.Program: Write a full program that satisfies the following specifications.
30.Declare two variables, one each for the length and width of a rectangular
field. Initialize each variable to an appropriate value. Identify, store, and
display the perimeter and area of the rectangular field.
31.
32.
33.
34.
35.
36.Declare and initialize a variable which stores the radius of a circle (initialize
the radius to a number of your choosing). If the circle is inscribed within a
square, find the area outside of the circle, but inside of the square (the
shaded region in the figure below). Store and display the calculated area. Use
3.14 or the statement Math.PI to represent pi.
37.

You might also like