Skip to content

Commit ed51b3b

Browse files
Create Myarray.java
1 parent d5c8b88 commit ed51b3b

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Myarray.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
/*
3+
System.in ---> Keyboard
4+
System.out---> Monitor n = int(input())
5+
class --> a collection of data & methods(or Functions)
6+
7+
In case of class --> The first letter will be CAPITAL LETTER
8+
In cas of method --> The name of the method, leave first word, from second words onwards
9+
the first letter of every word is CAPITAL.
10+
11+
EX: String, Integer, StringBuffer, Socket, ServerSocket --> classes
12+
nextInt(), equalsIgnoreCase(), toString(), parseInt(), compareTo() --> Functions
13+
The following program handles an array with n elements
14+
*/
15+
16+
import java.util.Scanner;
17+
18+
public class Myarray
19+
{
20+
public static void main(String args[])
21+
{
22+
int a[]; // only an array reference
23+
int n;
24+
int small, big;
25+
Scanner sc = new Scanner(System.in);
26+
System.out.println("Enter the size of the array");
27+
n = sc.nextInt();
28+
29+
a = new int[n]; // memory is allocated to the array. here it is a dynamic array
30+
31+
System.out.println("Enter values into array...");
32+
for(int i=0;i<n;i++)
33+
a[i] = sc.nextInt();
34+
35+
System.out.println("The array values are...");
36+
for(int i=0;i<n;i++)
37+
System.out.print(a[i]+" ");
38+
39+
40+
small = big = a[0];
41+
42+
for(int i=1;i<n;i++)
43+
{
44+
if(small > a[i])
45+
small = a[i];
46+
47+
if(big < a[i])
48+
big = a[i];
49+
}
50+
51+
System.out.println("Small = "+small);
52+
System.out.println("Big = "+ big);
53+
}
54+
}
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+

0 commit comments

Comments
 (0)