-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
50 lines (41 loc) · 1.48 KB
/
Main.java
File metadata and controls
50 lines (41 loc) · 1.48 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
package com.dj;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] myArray = new int[10];
myArray[0] = 45;
myArray[1] =1;
myArray[5] = 50;
double[] myDoubleArray = new double[10];
myDoubleArray[2]= 3.5;
System.out.println(myDoubleArray[2]);
int [] firstTen = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
System.out.println("first = " + firstTen[0]);
int arrayLength = firstTen.length;
System.out.println("length of array = " + arrayLength);
System.out.println("last = " + firstTen[arrayLength - 1]);
int [] newArray;
// newArray =new int[] {5, 4, 3, 2, 1 };
newArray = new int[5];
for (int i = 0; i < newArray.length; i++) {
newArray[i] = newArray.length - i;
}
for (int i =0; i< newArray.length; i++){
System.out.print(newArray[i] + " ");
}
System.out.println();
for (int element: newArray){
System.out.print(element + " ");
}
System.out.println();
System.out.println(Arrays.toString(newArray));
Object objectVariable = newArray;
if (objectVariable instanceof int[]){
System.out.println("objectVariable is really an int array");
}
Object[] objectArray = new Object[3];
objectArray[0] = "Hello";
objectArray[1] = new StringBuilder("World");
objectArray[2] = newArray;
}
}