-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayUse.java
More file actions
70 lines (57 loc) · 1.37 KB
/
ArrayUse.java
File metadata and controls
70 lines (57 loc) · 1.37 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
62
63
64
65
66
67
68
69
70
import java.util.Scanner;
public class ArrayUse {
public static int[] takeInput(){
Scanner s = new Scanner(System.in);
System.out.println("Enter size of array :");
int size = s.nextInt();
int inputArray[] = new int[size];
for(int i = 0; i < size; i++){
System.out.println("Enter "+i+" element");
inputArray[i] = s.nextInt();
}
return inputArray;
}
public static void print(int[] input){
for(int i = 0; i < input.length ; i++){
System.out.print(input[i]+" ");
}
}
public static int largest(int[] input){
int max = Integer.MIN_VALUE;
// int max = input[0];
for(int i = 0; i < input.length; i++){
if(max < input[i]){
max = input[i];
}
}
return max;
}
public static void incrementArray(int[] input){
for(int i = 0; i < input.length; i++){
input[i]++;
}
}
public static void main(String[] args) {
// int input1[] = new int[4];
// System.out.println(input1);
// print(input1);
// int[] input = new int[4];
// input[0] = 1;
// input[1] = 2;
int[] input = {1,2,3,4};
int[] input2 = {10,20,30,40};
print(input);
input = input2;
System.out.println();
print(input);
input2[3] = 100;
print(input);
// String name = s.nextLine();
// int[] input = takeInput();
// print(input);
//// System.out.println("Max :"+ largest(input));
// System.out.println();
// incrementArray(input);
// print(input);
}
}