490 likes | 503 Views
Learn key concepts, layout managers, event listeners, and array manipulation in Java Swing programming with review questions.
E N D
CHAPTER 7 & 8REVIEW QUESTIONS • ______ class is used to create a frame using Swing.
The default allignment of a FlowLayout manager is ______ allignment.
Adding radio button components to an object of ________ class will create a mutually exclusive relationship between them.
You can place multiple components inside a BorderLayout region.
What kind of Listener should be used for JButton and JTextField objects?
What kind of Listener should be used for JCheckBox and JRadioButton objects?
What import statement must you include in your code to use a ActionListener class?
The type of parameter in the setVisible() method of JFrame class is:
The type of parameter in the actionPerformed() method of ActionListener interface is:
The type of parameter in the itemStateChanged() method of ItemListener interface is:
Which method in the ActionEvent class is used to identify the source of an action event?
Given a JPanel object p, which of the followings is the correct statement to set the GridLayout manager of dimension 3 by 4 for p?
Each element of an array is accessed by a number known as a ________?
If n is the number of elements in an array, then the last subscript in this array is _____.
The array field that holds the number of elements in an array is ______.
To insert an item into an ArrayList object, you use this method.
An array’s size declarator can be a negative integer expression.
Both of the following declarations are legal and equivalent: int [] n; int n [];
Java compiler does not display an error message when it processes a statement that uses an invalid subscript.
Each row in a two-dimensional array can have a different length.
An ArrayList automatically expands in size to accommodate the items stored in it. True or false?
What will be the output when running the following program? public class MyClass { public static void main(String args[]) { int [][]a = { {3,5,1,2}, {0,1,3,4}, {1,2,9,8}}; int i=1; int j; for (j=1; j<=2; ++j){ a[i][j] += a[j][i]; } System.out.println(a[i][j-1]); } }
What results from the following fragment of code? int x = 1; String [] names ={“Fred”, “Jim”, “Sheila” }; names[--x] += “.”; for (int i = 0; i < names.length; i++) { System.out.println(names[i]); }
Given the following code fragment: int [] array = {2, 3, 6, 4, 1, 7, 9, 12}; int i = 1; int j = 2*i + 1; What is the value of array[j]?
Given the following code fragment: int [][] array = new int[5][]; for (int i = 0; i < 5; i++) array[i] = new int[i+1]; for (int i = 0; i < 5; i++) for (int j = 0; j < array[i].length; j++) array[i][j] = i + j; • How many elements does array have?
What import statement must you include in your code to use a Arrays and ArrayList class?
To delete an item from an ArrayList object, you use this method.
To determine the number of items stored in an ArrayList object, you use this method.
Given the following method: static int sum(int[] a) { int s = 0; for (int i=0; i<a.length; i++) if (a[i]%2==0) s += a[i]; return s; } And given the following array: int [] m = {1, 2, 3, 4, 5, 6}; What is the value of sum(m)?
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = 2*m[i-1]; for (int n: m) System.out.print(n+ " "); System.out.println();
Given the following code fragment: int [] array = {2, 3, 6, 4, 1, 7, 9, 12}; int i = 1; int j = 2*i + 1; • What is the value of array[j]?
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = 2*m[i]; for (int n: m) System.out.print(n+ " "); System.out.println();
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = m[i] + 2; for (int n: m) System.out.print(n+ " "); System.out.println();
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i< m.length–1; i++) m[i] = 2*m[i+1]; for (int n: m) System.out.print(n+ " "); System.out.println();
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = (m[i]%2==0 ? m[i]/2 : 3*m[i]+1); for (int n: m) System.out.print(n+ " "); System.out.println();
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=0; i<m.length; i++) m[i] = (i%2 == 0 ? 2*m[i] : m[i] + 2); for (int n: m) System.out.print(n+ " "); System.out.println();
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = m[i-1] + m[i]; for (int n: m) System.out.print(n+ " "); System.out.println();
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = m[i]- m[i-1]; for (int n: m) System.out.print(n+ " "); System.out.println();
What will be the output of the following code segment? int[] m = {1, 2, 3, 4, 5, 6}; for (int i=1; i<m.length; i++) m[i] = (m[i-1]< m[i] ? m[i] : m[i-1]); for (int n: m) System.out.print(n+ " "); System.out.println();