-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTest.java
More file actions
61 lines (52 loc) · 1.48 KB
/
Copy pathArrayTest.java
File metadata and controls
61 lines (52 loc) · 1.48 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.example.ArrayTest;
import java.util.Scanner;
public class ArrayTest {
Scanner scanner = new Scanner(System.in);
public static int a[];
public static int b[];
public void displayArray(int n[]){
for(int i = 0; i <= n.length-1; i++){
System.out.print(n[i] + " ");
}
System.out.println();
}
public void oneToN(int n){
a = new int [n];
for (int i = 0; i <= n-1; i++){
a[i] = i + 1;
}
}
public void swap(int n[]){
int m = n[0];
n[0] = n[n.length-1];
n[n.length-1] = m;
}
public void userArray(int n){
b = new int[n];
for(int i = 0; i <= n-1; i++){
b[i] = scanner.nextInt();
}
}
public void reverse(int n[]){
for (int i = 0; i <= n.length/2 - 1; i++){
int m = n[i];
n[i] = n[n.length-1-i];
n[n.length-1-i] = m;
}
}
public static void main(String[]args){
ArrayTest runner = new ArrayTest();
int c[] = {1, 2, 3, 4, 5, 6, 7};
int d[] = {1, 2, 3, 4, 5};
runner.displayArray(c);
runner.oneToN(20);
runner.displayArray(a);
runner.swap(c);
runner.displayArray(c);
System.out.println("Input n integers");
runner.userArray(5);
runner.displayArray(b);
runner.reverse(d);
runner.displayArray(d);
}
}