-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays.java
More file actions
146 lines (126 loc) · 3.36 KB
/
Arrays.java
File metadata and controls
146 lines (126 loc) · 3.36 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//public class Arrays {
// public static void main(String args[]){
// int[] marks = new int[3];
// marks[0] = 97;
// marks[1] = 94;
// marks[2] = 99;
// // System.out.println(marks[0]);
// // System.out.println(marks[1]);
// // System.out.println(marks[2]);
// for(int i = 0 ; i<3; i++){
// System.out.println(marks[i]);
// }
// }
//}
//import java.util.*;
//public class Arrays{
// public static void main(String args[]){
// Scanner sc = new Scanner(System.in);
// System.out.println("Enter the size of array");
// int size = sc.nextInt();
// int numbers[] = new int[size];
// //input
// for(int i=0; i<size; i++){
// numbers[i] = sc.nextInt();
// }
// System.out.println("Enter the number u want to search");
// int x = sc.nextInt();
// //output
// for(int i=0; i<size; i++)//for(int i=0; i<numbers.length ; i++)
// {
// if(numbers[i] == x){
// System.out.println(i+1 + " found at index : " + i);
// }
// }
// }
//}
// Result
// Enter the size of array
// 5
// 1
// 2
// 3
// 4
// 5
// Enter the number u want to search
// 4
// 4 found at index : 3
/*
//Take n array of names from the user and print them on the screen
import java.util.*;
public class Arrays{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
String names[] = new String[size];
//input
for(int i=0; i<size; i++){
names[i] = sc.next();
}
for(int i=0; i<size; i++){
System.out.println(names[i]);
}
}
}
// 5
// suruj
// asif
// paraj
// gaurav
// himaku
// suruj
// asif
// paraj
// gaurav
// himaku
/*
Find the maximum & minimum numbers in an array of integers.
import java.util.*;
public class Arrays{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int numbers[] = new int[size];
//input
for(int i = 0; i<size; i++){
numbers[i] = sc.nextInt();
}
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for(int i=0; i<size; i++){
if(numbers[i] > max){
max = numbers[i];
}
if(numbers[i] < min){
min = numbers[i];
}
}
System.out.println("Largest number is " + max);
System.out.println("Lowest number is " + min);
}
}
//Take an array of numbers as input and check if it is an array sorted in ascending orders
import java.util.*;
public class Arrays{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int numbers[] = new int[size];
// input
for(int i=0;i<size;i++){
numbers[i] = sc.nextInt();
}
boolean isAscending = true;
for(int i=0; i<size-1;i++){
if(numbers[i]>numbers[i+1]){
isAscending = false;
}
}
if(isAscending){
System.out.println("The array is sorted in ascending order");
}else{
System.out.println("The array is sorted in descending order");
}
}
}
*/