APCS Unit3&Unit4 If Loop Written
APCS Unit3&Unit4 If Loop Written
appropriate.
• Unless otherwise noted in the question, assume that parameters in method calls are not
null and that methods are called only when their preconditions are satisfied.
• In writing solutions for each question, you may use any of the accessible methods that
are listed in classes defined in that question.
• Writing significant amounts of code that can be replaced by a call to one of these
methods will not receive full credit.
1. Write a method that takes a string as an argument returns the word reversed. For
example
}
2. Write a method that will produce a grid of numbers by taking 2 integers as arguments.
For example
public static void gridit(int r, int c) if r was 2 and c was 2 would produce
0001
1011
3. Write a method that will replace all instances of a letter in a word with. For example the
method
He**o Wor*d
}
4. Create a method that will replace the number of letters in a word with random numbers.
For example:
5. Write a while loop that will count down by 2 from 100 until it gets to 0.
6. Write the loop from #5 as a for loop.
7. Write a nested for loop that will produce the pattern below.
XY XY XY XY
XY XY XY XY
XY XY XY XY
int x = 20;
while (x>0){
System.out.print(x);
x=3;
}
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN
IN JAVA.
1. Write a method that takes a string and an integer as an arguments and prints a new string splitting the
word based on the position of the integer passed and reversing the two parts so that the second part is
first and the first part is second. For example if the word Aquinas was passed with the integer 3 the
following would be printed out: inasAqu (split on the 3rd letter as the index and flipped)
2. Write a method that will take 2 strings as arguments. The first string will be a word and the second
string will be a letter(if you want to make it a char that is fine but your code must work with it). The
method will then count the occurrence of the letter in the work and print it the number of times the letter
appears in the word. For example if you passed Galat and a the method would produce 2.
4. Write a code segment that will do the the same as question #3 but as a while loop.
5. Using nested for loops (at least 2 loops) create the following pattern.
XXXXXX
XXXXXX
XXXXXX