...Problem Set 0
- Write a loop that prints out the numbers 0 to 5
- Write a loop that prints out the numbers 1 to 4
- Write a loop that prints out the sequence 5, 10, 15, 20
- Write a loop that prints out the odd numbers between 4 and 96.
- Write a program to print numbers between 4 and 96 that
are neither even, nor divisible by 3.
-
Here's an example of a code that creates a copy of an array, with
its elements reversed:
Reverse.java |
1 | public class Reverse { |
2 | static int[] reverse(int[] input) { |
3 | final int n = input.length; |
4 | int[] output = new int[n]; |
5 | for(int i=0;i<n;i++) |
6 | output[i] = input[n-i-1]; |
7 | return output; |
8 | } |
9 | public static void main(String[] args) { |
10 | int[] fvalues = new int[]{1,2,3,5,99}; |
11 | int[] rvalues = reverse(fvalues); |
12 | for(int i=0;i<rvalues.length;i++) |
13 | System.out.println(i+"] "+rvalues[i]); |
14 | } |
15 | } |
$ javac Reverse.java
| $ java Reverse
0] 99
1] 5
2] 3
3] 2
4] 1
|
Using it as inspiration, write a method called "evens" that creates a copy
of the array with the odd numbers removed.
|