0% found this document useful (0 votes)
40 views6 pages

2023 Exam Review

The document provides a review of Java introductory concepts including writing Java methods, using variables, loops, and if/else statements. It includes examples and questions to test understanding with blanks to be filled in. Key topics covered are writing Java code, using loops to iterate through ranges of numbers, and using if/else conditional logic.

Uploaded by

xxfloraxa
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)
40 views6 pages

2023 Exam Review

The document provides a review of Java introductory concepts including writing Java methods, using variables, loops, and if/else statements. It includes examples and questions to test understanding with blanks to be filled in. Key topics covered are writing Java code, using loops to iterate through ranges of numbers, and using if/else conditional logic.

Uploaded by

xxfloraxa
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/ 6

ICS3U Exam Review

Java Intro Review

1. Write the Java commands that will perform each of the following tasks:
a) write the method header for the main method for an application file
____________________________________________________________________________________

b) print one blank line

___________________________________________________________________________________

c) print the answer (just the numeric answer) to 45 multiplied by 12

____________________________________________________________________________________

d) print the 2 raised to the power of 5

____________________________________________________________________________________

e) print the following statement 22 divided by 3 is XX with decimals

____________________________________________________________________________________

f) print the following statement 22 divided by 3 is XX with an integer answer and remainders

_____________________________________________________________________________________________

g) place your first name in a variable

____________________________________________________________________________________

h) declare a variable that will hold a person’s hourly wage

____________________________________________________________________________________

i) declare a variable that will hold a person’s country of birth

____________________________________________________________________________________

2. A building has 56 floors. Each floor has 13 steps. It takes a person 2 seconds to climb each step. Write
a program that will print a message to the user indicating how many seconds it would take to climb to the top of
the building.

3. Calculate the interest earned on $1,000 for 6 years if the interest rate is 11% per year. Print a message
to the user explaining the answer.

Loop Review
FILL IN THE BLANKS. WRITE THE COMMANDS THAT WILL:
1. Display the word CENTENNIAL 6 times
for ( _____ x = 1 ; x <= _____ ; ________ ) {
System.out.println(“Centennial”) ;
}
2. Display a month of the year a specified number of times
sMonth = System.out.println (“Enter a month of the year”);
sNumber = System.out.println (“Enter how many times see this word”) ;
number = Integer.parseInt(sNumber) ;
for ( ______________ ; j <= _____ ; ________) ;
System.out.println( _________________) ;
}
3. Display the word WORLD 7 times and then the word SERIES 7 times after it.
for ( int y = 1 ; __________ ; _____________ ) {
System.out.println(_________________) ;
}
for ( int z = 3 ; ____________ ; _____________ ) {
System.out.println(_________________) ;
}
4. Display all the values for 20 to 30
for (int b = _____ ; ______________ ; ______________ ) {
System.out.println ( ____________________) ;
}
5. Set up a column that will have the word GRADE as the column heading and then type all the grades you have
spent at CENTENNIAL below it. Use 2 methods: first us the FOR loop, then use the WHILE loop.

System.out.println (“Grade); System.out.println(“Grade”);


for (int g=____ ; ____ ; ____ ) { g = _____ ;
__________________ ; while ( g __________________ ) }
} ____________________;
g = _____________ ;
}
6. Find out how much money the user earned throughout the week. Ask the user how much he/she earns each day
of the week ( a different amount each day) then calculate the total for the week.

total = ______________ ;
for ( int day = _____ ; day ______________ ; _____________ ) {
sPerDay = System.out.println (“How much did you earn day”
+ _____) ;
perDay = Double.parseDouble ( __________ ) ;
___________________________________;
}
System.out.println (“you earned $” + total + “this week”);
7. Determine how many years it takes a student to earn 30 credits. Ask the user how many credits were achieved in
each grade then print a final message that indicates the total number of credits over some number of years.
(assume variables have been declared but not yet initialized).

__________________ ;
__________________ ;
while ( totalCredits ________________ ) {
sCredits = System.out.println (“How many credits did you get
in Grade “ + _____) ;
credits = Integer.parseInt (sCredits) ;
totalCredits = ________________________ ;
years = _______________________________ ;
}
System.out.println (“You earned” + _______________ + “credits in “ +
______________ + “years”) ;

8. Determine the average sales of a company over the years from 2010 to 2013. Ask the user for the company’s
annual sales. Calculate and print the average sales of the company based on this data.

counter = _________________ ;
____________________ = 0 ;
for ( int year = _____ ; year ___________________ ; _______________ ) {
sSales = System.out.println (“What are your sales in “
+ ________ );
sales = Double. ___________________;
totalSales = _______________________________________________ ;
____________________________________________________________ ;
}
avgSales = ___________________________ ;
System.out.println(“Your average sales were $” + __________________________ ;

9. What will the output of the following program look like?


for ( int j = 7 ; j >= 1 ; j -= 2) {
for ( int k = 1 ; k <= 3 ; k++ ) {
System.out.print (“*”);
}
System.out.println();
}
IF STATEMENT REVIEW

1. What is a flowchart? Why is it used? What types of shapes are used to create one?

2. Indicate whether the word Hello will be printed. Answer YES or NO for each.

a = 16;
b = 29;
message = “Gold”;

a. if (a == 12) { ______
System.out.println ( “Hello” ) ;
}

b. if (b <= 29) { ______


System.out.println( “Hello” ) ;
}

c. if ( ! message.equals(“Silver”) ) { ______
System.out.println( “Hello” ) ;
}

d. if (a > 0) { ______
System.out.println( “Hello” ) ;
}

e. c = a * 10; ______
if (c > b) {
System.out.println( “Hello” ) ;
}

f. if (a <= b) { ______
d = b + 1;
}
if ( d > 12) {
System.out.println( “Hello” ) ;
}

g. if ( message.equals(“Bronze”) ) { ______
System.out.println( “GoodBye” ) ;
}
System.out.println( “Hello” ) ;

h. if ( b != 0 ) { ______
b = b + 1;
}
if (b == 30) {
System.out.println(“Hello”);
}

2. Fill in the blanks. This program will ask the user for a number and determine if it is positive or negative.

sNum = System.out.println (“Please enter a number”);


num=Integer.parseInt(sNum);
if ( num ____________________________ ) {
word = “Positive” ;
} else {
_____________________________ ;
}
System.out.println( num + “is a “ + _____________ + “number”);

3. Fill in the blanks for the following program. It will count how many people live in
Puslinch.

c = _______________________;
while ( ____________________ ) {
city = System.out.println (“Where do you live –
enter ZZZ to terminate”);
if ( ______________________________ ) {
______________________________;
}
}
System.out.println(“There are” + ________ + “who live in
Puslinch”);

4. A person over age 65 gets 10% off. No discount for others.


price = 200;
discount = 0;
sAge = System.out.println(“Please enter your name”);
age = Integer.parseInt(sAge);
if (age >= 65) {
System.out.println(“You are eligible for a fare discount”);
discount = price * 10/100;
}
price = price – discount;
System.out.println(“The discount is “ + ___________________ );
System.out.println(“The fare is” + _____________________);

5. Fill in the blanks.


a. print the names of all people from Calgary or Edmonton
if (city.equals __________________ _____ _________________ ) {
System.out.println(name);
}

b. print the names of all people who are between 17 and 25


if ( age ________________ _____ _____________ ) {
System.out.println(name);
}
c. count how many people are happy and over age 45
c=0;
gender = System.out.println(“Enter your general state of being”);
sBirth=System.out.println(“Enter year of birth”);
birth = Integer.parseInt(sBirth);
age = ________________ ;
if ( _________________ _______ ___________________ ) {
_____________________________ ;
}
System.out.println(“There are “ + _____________ + “happy people over age
45”);

6. Write the programs that will:

a. Ask the user for his/her name and age. If the person is under 16, tell him/her what year he/she will be
eligible to drive.

b. Ask the user for 5 numbers. Count how many values were negative. Also indicate what percentage of
numbers were negative.

c. Ask the user to enter the capital of Iowa. Count the number of times it takes to get the correct response.

d. Ask the user what the sum of 2 random numbers is. The command to generate a random number is:
Allow the user 3 attempts. If his/her answer is correct, print a message and indicate the total number of
attempts. If his/her answer is incorrect after 3 attempts, print an appropriate message then provide the
correct answer.

e. Ask the user to enter a negative number. If an invalid number is entered, print an error message.
Continue accepting a number until a valid number is entered. (error checking program).

f. Ask the user for a letter between A and D. Only allow valid data to be entered. Print an error message if
data is invalid.

You might also like