-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHW6P1.java
More file actions
25 lines (25 loc) · 813 Bytes
/
HW6P1.java
File metadata and controls
25 lines (25 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner;
public class HW6P1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n;
int[] array;
System.out.print("How many integers? ");
n = input.nextInt();
array = new int[n];
System.out.print("Enter " + n + " integers: ");
for(int i = 0; i < array.length; i++) {
array[i] = input.nextInt();
}
System.out.print("Reversed:");
for(int count = array.length; 0 < count; count--) {
System.out.print(" " + array[count - 1]);
}
System.out.println();
System.out.print("Every other:");
for(int i = 0; i < array.length; i+=2) {
System.out.print(" " + array[i]);
}
System.out.println();
}
}