Created
February 16, 2020 22:26
-
-
Save alimuhammed056/3143ee9c879e26eab7cefb53cba1c73d to your computer and use it in GitHub Desktop.
Java5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewClass { | |
public static void main(String[] args) { | |
if(args!=null && args.length>0){ | |
System.out.println(args[0]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewClass1 { | |
public static void main(String[] args) { | |
int x[] = new int[3]; | |
// System.out.println(x.length); | |
x[0] = 7; | |
x[1] = 8; | |
x[2] = 2; | |
// System.out.println(x[2]); | |
for(int i =0; i<x.length; i++){ | |
System.out.println(x[i]); | |
} | |
//element from array | |
for(int j : x){ | |
System.out.println(j); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
/* | |
*/ | |
public class NewClass10 { | |
public static void main(String[] args) { | |
int x[][] = new int[3][3]; | |
System.out.println(x.length); | |
System.out.println(x[1].length); | |
x[0][0] = 4; | |
x[0][1] = 7; | |
x[0][2] = 9; | |
x[1][0] = 2; | |
x[1][1] = 4; | |
x[1][2] = 6; | |
x[2][0] = 9; | |
x[2][1] = 5; | |
x[2][2] = 1; | |
for(int i =0; i<x.length ; i++){ | |
for(int j =0; j<x[i].length ; j++){ | |
System.out.print(x[i][j]+" "); | |
} | |
System.out.println(""); | |
} | |
for(int j[] : x){ | |
for(int k : j){ | |
System.out.print(k+" "); | |
} | |
System.out.println(""); | |
} | |
for (int i = 0; i <x.length; i++) { | |
System.out.println(Arrays.toString(x[i])); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*/ | |
public class NewClass11 { | |
public static void main(String[] args) { | |
int x[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; | |
int j = x.length - 1; | |
int sum = 0; | |
for (int i = 0; i < x.length; i++) { | |
sum = sum + x[i][j]; | |
j--; | |
} | |
System.out.println(sum); | |
int sum1 = 0; | |
for (int i = 0; i < x.length; i++) { | |
sum1 = sum1 + x[i][i]; | |
} | |
System.out.println(sum1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
while | |
*/ | |
public class NewClass2 { | |
public static void main(String[] args) { | |
int i =0; | |
while(i<5){ | |
System.out.println(i); | |
i++; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
do while | |
*/ | |
public class NewClass3 { | |
public static void main(String[] args) { | |
int i = 0; | |
do{ | |
System.out.println(i); | |
i++; | |
}while(i<5); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewClass4 { | |
public static void main(String[] args) { | |
int x[] = {1, 2, 3, 4}; | |
System.out.println(x.length); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Scanner; | |
/* | |
*/ | |
public class NewClass5 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter array length"); | |
int length = sc.nextInt(); | |
int x[] = new int[length]; | |
for(int i =0 ; i< x.length ; i++){ | |
System.out.println("Enter element @ index "+i); | |
x[i] = sc.nextInt(); | |
} | |
System.out.println(Arrays.toString(x)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
/* | |
*/ | |
public class NewClass6 { | |
public static void main(String[] args) { | |
String [] str = {"A","B","C","D"}; | |
Random r = new Random(); | |
int i = r.nextInt(str.length);//index | |
System.out.println(str[i]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewClass7 { | |
public static void main(String[] args) { | |
String [] str = {"A","B","C","D","E"}; | |
if(str.length%2==0){ | |
System.out.println(str[str.length/2 -1 ]+" "+str[str.length/2]); | |
} else{ | |
System.out.println(str[str.length/2]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*/ | |
public class NewClass8 { | |
public static void main(String[] args) { | |
int x[] = {4,8,9,7,9,3}; | |
int sum = 0; | |
for (int i = 0; i < x.length; i++) { | |
sum = sum + x[i]; | |
} | |
System.out.println(sum); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*/ | |
public class NewClass9 { | |
public static void main(String[] args) { | |
int x[] = {4,8,9,7,9,3}; | |
int sum =0; | |
for(int j : x){ | |
sum = sum + j; | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment