-
Notifications
You must be signed in to change notification settings - Fork 4
/
ArrayTest.java
91 lines (62 loc) · 1.56 KB
/
ArrayTest.java
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.Scanner;
class Numbers{
int num[];
void createArray( int l ){
num = new int[l];
System.out.println("Array Created");
}
void inputArray(){
Scanner sc = new Scanner(System.in);
for(int i = 0; i < num.length; i++){
System.out.println("Enter the marks in the Array");
num[i] = sc.nextInt();
}
}
void displayArray(int arr[]){
//System.out.println("Marks Stored in Array");
for(int i =0; i < arr.length; i++){
System.out.println("num["+i+"] = "+ arr[i]);
}
}
void bubbleSort(){
int temp, i ,j;
for(j = 0; j < num.length; j++){
for(i = 0; i < num.length - 1; i++){
if(num[i] > num[i+1]){
temp = num[i];
num[i] = num[i+1];
num[i+1] = temp;
}
}
}
}
int[] copyArray(){
int temp[] = new int[num.length];
for(int i = 0; i < num.length; i++ ){
temp[i] = num[i];
}
return temp;
}
void modifyArray(int [] temp , int m){
for(int i = 0; i < temp.length; i++)
temp[i] += m;
}
}
class ArrayTest{
public static void main(String[] args) {
Numbers n = new Numbers();
n.createArray(5);
n.inputArray();
n.bubbleSort();
int test[] = n.copyArray();
System.out.println("Values from test array");
n.displayArray(test);
System.out.println("Values from num array");
n.displayArray(n.num);
int t[] = {1,4,6,7,9,34};
int m = 10;
n.modifyArray(t, m);
for(int i = 0; i < t.length; i++)
System.out.println("t[ "+i+" ] = "+ t[i]);
}
}