str2.indexOf("s");
What is at arr4[arr4.length-1]?
4
The 'Book' class has instance variables 'title', 'author', and pages with constructor header shown below:
public Book(String title, String author, int pages)
{ /*Implementation not shown */ }
Write a line of code that constructs a 'Book' object in main and stores it in a new object variable.
Book gatsby = new Book("The Great Gatsby", "F. Scott Fitzgerald", 192);
arrList1.add(14);
arrList1.add(18);
arrList1.remove(0);
What is in arrList1?
[5, 8, 10, 14, 18]
System.out.print(twoDArray2[1][0]);
What will print?
2
Will str4.compareTo(str1) return a value that is greater than or less than 0?
Greater than 0
Cake[2] = cake15;
Cake[1] = Cake[0];
What is in cakes?
[cake1, cake1, cake15, cake12]
Write a constructor definition for a 'Song' class which connects the instance variables 'title', 'artist', and 'track' to the parameters of the constructor header.
public Song(String title, String artist, int track) {
this.title = title;
this.artist = artist;
this.track = track;
}
System.out.print(arrList2.get(1) + " " + arrList2.get(0) + " " + arrList2.get(arrList2.size()-1));
What will print?
you my us
for(int r = 0; r<twoDArr1.length; r++){
for(int c = 0; c<twoDArr1[0].length; c++){
System.out.print(twoDArr1[r][c] + " ");
}
}
What will print?
Five Four Three Two One Zero
String str5 = str4.substring(6, 11);
What is str5?
he Ja
for(int i =0; i<arr1.length; i++){
if(arr1[i] >= 2.0){
System.out.print(arr1[i])+" "; }
}
What will print?
2.5 7.8 9.3
Write a constructor for the Teacher class, which takes in a 1D array of strings called "classes" and a 2D array of integers called "grades" and stores them in appropriate instance variables.
public Teacher(String[] classes, int[][] grades) {
this.classes = classes;
this.grades = grades;
}
Write a command to place the value of 5.5 at the very beginning of arrList4 so that it replaces 8.6.
arrList4.remove(0);
arrList4.add(0, 5.5);
OR
arrList4.set(0, 5.5);
Double sum = twoDArr3[1][2] + twoDArr3[0][3] + twoDArr3[2][3];
24.7
(2.2 + 10.2 + 12.3)
String str6 = str2.substring(4);
What is str6?
arr3[0] = arr3[arr3.length-1]
arr3[1] = arr3[arr3.length-2]
What is in arr3?
[false, true, true, true, false]
Write a 'Circle' class with appropriate instance variables for an x-coordinate, y coordinate, and radius. Include the constructor definition as well.
public class Circle {
private int xCoord;
private int yCoord;
private int radius;
public Circle(int xCoord, int yCoord, int rad) {
this.xCoord = xCoord; //etc.
}
}
int num = arrList1.size() + arrList2.size() - arrList3.size();
What is num?
6
for(int c = 0; c<twoDArr2[0].length; c++){
for(int r = 0; r<twoDArr2.length; r++){
System.out.print(twoDArr2[r][c] + " ");
} System.out.println();
}
5 2
5 2
6 6
7 0
9 12
String str7 = str1.substring(10,str1.length()-1) + str1.substring(0,3);
What is str7?
jobFRQ
Which of the arrays would be appropriate for a binary search (disregarding the length of the arrays)?
arr2, arr4
The Math class includes a static method called random(). Write the command that will generate a random number to select one of the months of the year (from 1 to 12).
Math.random()*12 +1;
Write the commands that will change arrList2 to contain ["I", "me", "my", "you", "we", "us"]
arrList2.add(0, "me");
arrList2.add(0, "I");
for(int r = twoDArr3.length-1; r>=0; r--){
for(int c = twoDArr3[0].length-1; c>=0; c--){
System.out.print(twoDArr3[r][c] + " ");
} System.out.println();
}
12.3 18.8 16.5 11.5
10.4 2.2 4.5 9.6
10.2 9.4 8.4 7.5