-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperation_in_array.java
38 lines (33 loc) · 1.21 KB
/
operation_in_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
import java.util.Scanner;
import javax.swing.text.html.parser.Element;
public class operation_in_array {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
// int [] marks = {20, 40, 60, 80, 55};
// System.out.println(marks[5]);
// System.out.println(marks.length);
// to find length of an array
// to print the element of array in reverse order
// int [] marks = {20, 40, 60, 80, 55};
// for(int i=(marks.length-1); i>=0; i--){
// System.out.println(marks[i]);
// }
// // accessing elememts of array in another way
// System.out.println("Array elements:");
// for(int element : marks){
// System.out.println(element);
// }
// user defined array
System.out.println("Enter array size:");
int size = sr.nextInt();
int [] marks = new int[size];
System.out.println("Enter array elements:");
for(int i=0; i<size; i++){
marks[i] = sr.nextInt();
}
System.out.println("Elements in reverse order:");
for(int i=marks.length-1; i>=0; i--){
System.out.println(marks[i]);
}
}
}