0% found this document useful (0 votes)
29 views8 pages

2 - ICS3U Exam Review Modified Jan 2025

This document is an exam review for a Java programming course (ICS 3U1) that covers a wide range of topics including variable types, loops, arrays, methods, and file handling. It contains numerous questions and coding exercises designed to test knowledge and understanding of Java programming concepts. The review also includes sections on tracing code and communication practice, as well as programming practice problems.

Uploaded by

diyamehra0317
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)
29 views8 pages

2 - ICS3U Exam Review Modified Jan 2025

This document is an exam review for a Java programming course (ICS 3U1) that covers a wide range of topics including variable types, loops, arrays, methods, and file handling. It contains numerous questions and coding exercises designed to test knowledge and understanding of Java programming concepts. The review also includes sections on tracing code and communication practice, as well as programming practice problems.

Uploaded by

diyamehra0317
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/ 8

PROGRAMMING IN JAVA - EXAM REVIEW (ICS 3U1)

1. What are the 4 types of integer variables, from smallest to largest?


2. What two types of variables hold real numbers (i.e. with
decimals)?
3. What type of variable holds alpha-numeric data (i.e. letters, numbers, special
characters and spaces)?
4. What type of variable holds a single character?
5. What 2 values can a boolean variable hold?
6. Can several variables of the same type be declared on the same line? If so, how?
7. Can several variables of different types be declared on the same line? If so, how?
8. Name 4 rules for choosing variable names.
9. Declare a variable to hold a person’s first name.
10. Declare a variable to hold Bill Gates’ bank account balance.
11. Declare a variable to hold the position number in an array.
12. Name two ways to give a variable a value?
13. If x = 5, given the code y = x ++; what is the final value of x and y?
14. If x = 5, given the code y = ++ x; what is the final value of x and y?
15. Explain the difference between question 13 and question 14.
16. Given this statement : int num1, num2 = 0; will num1 have the value of 0?
17. Show the 3 ways to add 1 to the value stored in variable count?
18. How do you get information to be outputted onto the screen on different lines?
19. How do you get information to be outputted onto the screen on the same line?
20. How do you create a blank line on the screen?
21. How do you pick a random number from 1 to 50 and store it in the integer variable
num1.
22. What set of mathematical rules does Java follow?
23. List the 5 mathematical operators (symbols) used in Java.
24. List the 6 ways that two numeric values can be compared (comparison operators).
25. List 4 ways to compare two string values.
26. What would be true about s1 and s2 given the following equations:
a) s1.compareTo (s2) > 0
b) s1.compareTo (s2) == 0

c) s1.compareTo (s2) < 0

27. List the 3 lines of coding required if you are need to get input from the keyboard?
28. How do you get alpha-numeric input from the user (via the keyboard)?
29. How do you get numeric input from the user (via the keyboard) (2 steps)?
30. List the three ways to perform repetition.
31. Write the first line to begin a repetition from -5 to 5 by 1.
32. Write the first line to begin a repetition from 5 to -5 by 1.
33. Write the first line to begin a repetition from 100 to 0 in steps/decrements of 5.
34. Explain how to modify #33 so that the user may input the starting and ending values
instead of always using 100 and 0.
35. When would a programmer want to use a counted loop?
36. What is the command to leave a loop early?
37. How could you create an infinite loop?
38. Explain when a programmer would want to use a while loop?
39. Explain when a programmer would want to use a do/while loop?
40. What structure allows a programmer to do one set of tasks when one condition is true
and another sets of tasks when the condition is not true, or a different condition is true?
41. How many conditions can be stated?
42. If the programmer wants two conditions to be true, what symbol is placed in between
the conditions?
43. If the programmer wants at least one of the conditions to be true, what symbol is
placed between the conditions?
44. If the programmer wants only one of the conditions to be true, what symbol is placed
between the conditions?
45. Is the statement correct? if (num > 5 && < 10); If not, correct the problem.
46. What word(s) tells the computer to complete a set of sets if all other conditions are
false?
47. What word(s) tells the computer that you are beginning the 2nd, 3rd, etc. possibilities?
48. Is it always necessary to have an else statement in a program?
49. What is an array?
50. Name 2 benefits of using an array over multiple single variables.
51. What is a 2-D array?
52. Name 2 situations when a programmer might choose to use a 2-D array.
53. Name 2 limitations on the use of arrays in Java.
54. Create an array to hold the names of 30 people.

55. Create an array to hold 20 marks for each of 30 students.


56. Explain how to create an array in which the user, instead of the programmer, will
choose the number of elements.
57. Name 3 ways to place values into an 1-dimensional array.
58. What position number does an array start at? Is it possible to change the starting
point?
59. Can the elements in an array be accessed in any order, or must they be accessed
sequentially (i.e. 0, 1, 2, 3, etc.)?
60. Can the entire array ever be accessed (ex. to be printed out) all at once, or are you
required to access each element individually?
61. What is the command to find the length of an array called list?
62. Name 3 differences between a String and a char.
63. Write the command to find the length of the String word.
64. What is catenation?
65. What is the result of the following statement:
System.out.println (5 + 5 + “ is the number");
66. What is the result of the following statement:
System.out.println (“The number is ” + 5 + 5); 67.
Explain the difference between 66 and 67 (above).
68. What is the purpose of the charAt command?
69. Write the code to find the last letter of the String word.
70. How would you convert an entire word into lower case?
71. How would you convert a single letter into upper case?
72. How would you decide if a single character was a blank space? (2 ways)
73. How would you decide if a single character was a letter?
74. Explain how you would decide if a single character was a consonant?
75. What is the purpose of the indexOf command?
76. Name one situation where a programmer might choose to use the indexOf command?
77. What value does the indexOf command return if the character(s) are not found?
78. What does the substring command do?
79. Given String word =”practise”, what is the result of the following statement?
System.out.println (word.substring (1,5)); 80.
What is a method?

81. What is the purpose for dividing a larger program into smaller methods?
82. What is a procedure-style (void) method?
83. What is a function-style (non-void) method?
84. When would a programmer choose to use a function-style method over a procedure
style method?
85. What is a return type in a method?

86. What is the return type in the method declaration: void AddNum ()
87. What are parameters, in general? In other words, what is their purpose in
programming?
88. What are formal parameters (2 points)?
89. What are actual parameters (2 points)?
90. Write the method declaration for a method called SortNum which has two parameters
(an integer array and the size of the array), and which returns the array to the main
program.
91. How do you return a value to the main program from a method? (3 points)
92. What is a class?
93. What is an object?
95. What are instance variables?
96. Can the main program access instance variables? If so, how?
97. Can you prevent the main program from accessing instance variables. If so, how?
98. What should be true about all of the methods inside of a class?
99. Declare an object called stu which belongs to the class Students.
100. If Students contained a variable called total, assign total the value of 5 (from the main
program).
101. Write the two lines of code to open file “names.txt” so that data may be read from it.
102. Write the line of code to open file “names.txt” to allow data to be written to it.
103. Should you have a file open to be read from and written to at the same time?
104. Can you have a file open to be read from and written to in the same program? If
so, what do you have to do in between?
105. Can you read from file and keyboard in the same program? If so, how?
106. Name 9 places where you would place an open curly bracket { in a program.
ICS3U1 EXAM REVIEW - TRACING

1. for (int count = 1 ; count <= 12 ; count += 4)


{
System.out.print (count + " ");
System.out.println (count * count);
}

2. int num = 1;
do
{
System.out.println (num);
num *= 2;
}
while (num <= 20);
System.out.println ("Finished!");

3. int f [] = new int [10];


f [0] = 1;
f [1] = 1;
for (int x = 2; x < 10; x++)
{
f[x] = f [x - 1] + f [x - 2];
}
for (int count = 0; count < 10; count++)
{
System.out.println (f[count]);
}
ICS3U1 EXAM REVIEW - COMMUNICATION PRACTICE
In your own words, describe how to solve the following problem. DO NOT WRITE THE
PROGRAM!! You may use flowcharting, diagrams, point-form or any other method with
which you are comfortable. Be sure to break your points down into step-by-step
instructions. You will be awarded marks based on how well your solution would work and
how detailed your solution is. (10 marks)

Given a list of students and a list of their marks in a class (which are stored in a
file called info.txt), arrange the list alphabetically by name and, if two people
have the same name, place the person who has the highest mark first (out of all
of the marks). Then, write the sorted list back to the file.
ICS3U1 EXAM REVIEW - PROGRAMMING PRACTICE
1. Write a for loop to output all even numbers from 1 to 50.
2. Write a for loop to output all odd numbers from 50 to 1.
3. In a 1-D array with 25 values called names, find the name “Bob” and output the
position that it was found in, or the message “Not Found” if it was not in the list.
4. Write a method which, given a String as its parameter, count how many vowels are in
the String and output the result on the screen. Do not send the result back to the
main method.
5. Write a method which will create an array of 50 strings, read in the Strings from the
user, and determine the total numbers of characters in the array.
6. Write a method which will read in 10 words from the user and create and output a
new String called sentence, which contains all 10 words, separated by spaces, and
ending with a period.
7. Create a method which will open a file called “numbers.txt” and read in an
undetermined number of positive integers from the user (the user will type -1 when
they are finished). You will then create an array to hold those integers, read them
back from the file into the array and find the average of the numbers.
8. Write a method which, given an array of Strings and a char as the parameters, will
find the number of Strings which contained that char (in any position). The method
will return that number back to the main program.
9. Write a main method which will allow the user to choose from the following methods
written above: 5, 6, 7, and 8. The user should also have the option to exit. Assume
that these methods belong to a class called ExamPrep and declare an object
accordingly. Declare any necessary variables and be sure to pay attention to which
methods require parameters and which methods are returning values to the main
program. The program will repeat until the user chooses the exit option and should
include an error message if the user chooses an invalid option.

You might also like