-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.java
80 lines (56 loc) · 2.09 KB
/
array.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
import java.util.*;
public class array {
public static void main(String[] args) {
// int arrayName = {12,43,54,43};
// int[] arrayName = new int[size];
System.out.println("enter size of array: ");
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int number[]= new int[size];
// take i values..
for(int i=0; i<size; i++){
System.out.println("enter values for array: ");
number[i]=sc.nextInt();
}
// print value of i...
// for(int i=0; i<size; i++){
// System.out.println("the value of array are: ");
// System.out.println(number[i]);
// }
// Question..
// found value of x in array...
// System.out.println("Enter value of x:");
// int x= sc.nextInt();
// for(int i=0; i<number.length; i++){
// if(number[i]== x){
// System.out.println("X found at index:" +i);
// }
// }
// Question .. find max and minimum..
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for(int i=0; i<number.length; i++){
if(number[i]<min){
min = number[i];
}if(number[i]>max){
max=number[i];
}
}
System.out.println("largest number is: " +max);
System.out.println("Smallest number is: " +min);
// Question .. sorted array in acending order..
boolean isAscending = true;
for(int i=0; i<number.length-1; i++){
// terminate
if(number[i]>number[i+1]){
// decending order..
isAscending = false;
}
}
if(isAscending){
System.out.println("the array in sorted in ascending order..");
}else{
System.out.println("the array is not sorted in ascending order..");
}
}
}