Make a for loop that stops when i=5, printing i at each iteration
for(int i=0; i=5; i++){
System.out.println(i);
}
How do you find the size of array students
students.length
How do you find the length of arraylist students
students.Size()
What java class is used to read the text file?
Scanner class
File class
What is recursion?
Calling a function from inside a function?
Name 3 loops in java
for, for-each, while, do-while
and more!
How do you change the variable at index 3, to the number 10 in array numbers?
numbers[3] = 10;
How do you change the variable at index 3, to the number 10 in arraylist numbers
numbers.set(3,10);
Write the statement for declaring a file from a file path using the file path "./bands.txt"
File file = new File("./bands.txt");
What is the part of a recursive statement that stops doesn't call the function called?
The base case
How would you write an infinite for loop
so many answers
Declare an array names with the names Billy and Bob
String[] names = {"billy", "Bob"};
Declare an arraylist names and add billy and bob
ArrayList<String> names = new ArrayList<>();
names.add("Billy");
names.add("Bob");
Write the line for the scanner to read in the file path with the file name f
Scanner scnr = new Scanner(f)
What is the general structur of a recursive function
if - base case
else - returns recursiveFunction again modifying n
}
How can you use a loop to find the maximum value in an array?
int max = 0;
for(int i=0; i<nums.length; i++){
if(nums[i] > max) max = nums[i];
}
Declare an array students with a size of 5
String[] students = new String[5];
Delcare an arraylist students with a size of 5
Arraylist<String> students = new Arraylist<>(5);
How do you grab the next line of a text file using scanner
scnr.nextLine();
Describe a base case in recursion. Why is it necessary?
Tells the recursive function when to stop calling itself. It prevents infinite loops.
How do you iterate through a 2d array using loops?
Concider 2d array seating
Nested for loops!
for(int i =0; i<seating.length;i++){
for(int j=0; j<seating[i].lengthj++){
sop(seating[i][j];
}
}
Use the java class Arrays to copy students to the new array of strings kids
String[] kids = Arrays.copyOf(students, students.length);
Use the Arraylist method to copy students to an ARRAY of strings kids
String[] kids = students.toArray();
How would you split the file text into an array by a comma?
sc.useDelimiter(",");
Provide an example of a simple recursive method that computes factorial of a number.
static int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}