Skip to content

Commit d59fb4c

Browse files
commit
1 parent 0c3cb07 commit d59fb4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+976
-4
lines changed

1.DataType/ClassCodes/Program10.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ClassCodes;
2+
3+
public class Program10 {
4+
5+
int x =10; //Instance variable or Global variable || Stored at location in JVM-
6+
public static void main(String[] args) {
7+
8+
int y=20; // Local Variable || Stored at location in JVM- Stack Section
9+
}
10+
}

1.DataType/ClassCodes/Program2.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ClassCodes;
2+
3+
public class Program2 {
4+
public static void main(String[] args) {
5+
// jerNo =18; //Error : can't find symbol
6+
7+
// System.out.println(jerNo);
8+
9+
}
10+
}

1.DataType/ClassCodes/Program3.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ClassCodes;
2+
3+
public class Program3 {
4+
public static void main(String[] args) {
5+
6+
byte jerNo = 127; //Can't Give the error
7+
8+
// byte jerNo = 128; // It will give the number beacause the range of the byte datatype is -128 to 127
9+
10+
11+
System.out.println(jerNo);
12+
}
13+
}

1.DataType/ClassCodes/Program4.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ClassCodes;
2+
3+
public class Program4 {
4+
public static void main(String[] args) {
5+
6+
byte var1 = 18;
7+
byte var2 = 18;
8+
9+
// var1 = var1 + var2; // error: incompatible types: possible lossy conversion from int to byte (Compile time error)
10+
// Runtime value generated in var1 and the addition of two byte is 36 but at runtime number
11+
// generated by java is by default is int. therefore the error lossy conversion from int to byte
12+
13+
System.out.println(var1);
14+
}
15+
}

1.DataType/ClassCodes/Program5.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package ClassCodes;
2+
3+
public class Program5 {
4+
public static void main(String[] args) {
5+
6+
short var1 = 10;
7+
short var2 = 20;
8+
9+
// var1 = var1 + var2; //same error in program4
10+
System.out.println(var1);
11+
12+
System.out.println(var1+var2);
13+
}
14+
}

1.DataType/ClassCodes/Program6.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ClassCodes;
2+
3+
public class Program6 {
4+
public void main(String[] args) {
5+
6+
// float f1 =7.5;
7+
// float f2 = 7.5; // error: incompatible types: possible lossy conversion from double to float
8+
9+
// float f1 =7.5f;
10+
// float f2 = 7.5f; //to remove the error
11+
12+
// System.out.println(f1);
13+
// System.out.println(f2);
14+
15+
System.out.println("Hello");
16+
17+
}
18+
}

1.DataType/ClassCodes/Program7.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ClassCodes;
2+
3+
public class Program7 {
4+
// public void main(String[] args) {
5+
6+
// System.out.println("Hello"); //Error: 'main' method is not declared 'public static'
7+
8+
// }
9+
10+
// static void main(String[] args) {
11+
// System.out.println("Hello"); ////Error: 'main' method is not declared 'public static'
12+
// }
13+
14+
15+
public static void main(int[] args) {
16+
System.out.println("Hello");
17+
18+
19+
}
20+
}

1.DataType/ClassCodes/Program8.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ClassCodes;
2+
3+
public class Program8 {
4+
public static void main(int[] args) {
5+
System.out.println("Hello"); //Runtime Error: error: can't find main(String[]) method in class: ClassCodes.Program8
6+
7+
}
8+
9+
}

1.DataType/ClassCodes/Program9.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ClassCodes;
2+
3+
public class Program9 {
4+
static void main(String[] args) {
5+
6+
System.out.println("Helo"); //Runtime error: 'main' method is not declared 'public static'
7+
8+
}
9+
}

1.DataType/Program3.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class Demo{
22

3-
public static void main(String[] args){
3+
public void main(String[] args){
44

5-
float var1 = 12.5f;
6-
// float var2 = 23.5f;
5+
// float var1 = 12.5f;
6+
// // float var2 = 23.5f;
77

8-
System.out.println(var1);
8+
// System.out.println(var1);
99
}
1010
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

3.Array/PracticeCodes/Program1.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
/*
3+
Program 1 : WAP to create 1-D array of length n from user and also take value
4+
from user and print whole 1-D array.
5+
*/
6+
7+
8+
9+
package PracticeCodes;
10+
11+
import java.io.BufferedReader;
12+
import java.io.InputStreamReader;
13+
14+
public class Program1 {
15+
public static void main(String[] args)throws Exception {
16+
17+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
18+
19+
System.out.println("Enter the size of the array: ");
20+
int size = Integer.parseInt(br.readLine());
21+
22+
System.out.println("Enter the element of array: ");
23+
24+
int a[] = new int[size];
25+
26+
for(int i=0;i<a.length;i++)
27+
{
28+
a[i] = Integer.parseInt(br.readLine());
29+
}
30+
31+
System.out.println("The array becomes: ");
32+
33+
for(int i=0;i<a.length;i++)
34+
{
35+
System.out.print(a[i]+" ");
36+
}
37+
38+
39+
40+
}
41+
42+
}

3.Array/PracticeCodes/Program10.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Program 9 : Write a program that creates integer array of 10 elements,
3+
accepts values of arrays and Find sum of all odd numbers
4+
*/
5+
6+
package PracticeCodes;
7+
8+
import java.io.*;
9+
10+
public class Program10 {
11+
12+
public static void main(String[] args) throws IOException {
13+
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
16+
System.out.println("Enter the size of array : ");
17+
int size = Integer.parseInt(br.readLine());
18+
19+
int[] arr = new int[size];
20+
21+
System.out.println("Enter the element of array : ");
22+
for (int i = 0; i < size; i++) {
23+
24+
arr[i] = Integer.parseInt(br.readLine());
25+
}
26+
int Sum = 0;
27+
for (int i = 0; i < size; i++) {
28+
29+
if (arr[i] % 2 == 1) {
30+
31+
Sum += arr[i];
32+
}
33+
}
34+
System.out.println("Sum of All odd numbers : " + Sum);
35+
}
36+
}

3.Array/PracticeCodes/Program11.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
/*
3+
Program 10 : Write a program that creates integer array of elements,
4+
accepts values of arrays and Search for a number in an array of 10.
5+
*/
6+
7+
package PracticeCodes;
8+
9+
import java.io.*;
10+
11+
public class Program11 {
12+
13+
public static void main(String[] args) throws IOException {
14+
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
17+
System.out.println("Enter the size of array : ");
18+
int size = Integer.parseInt(br.readLine());
19+
20+
int[] arr = new int[size];
21+
22+
System.out.println("Enter the element of array : ");
23+
for (int i = 0; i < size; i++) {
24+
25+
arr[i] = Integer.parseInt(br.readLine());
26+
}
27+
28+
System.out.println("Enter the searching element : ");
29+
int Search = Integer.parseInt(br.readLine());
30+
31+
boolean flag = false;
32+
33+
for (int i = 0; i < size; i++) {
34+
35+
if (arr[i] == Search) {
36+
37+
flag = true;
38+
System.out.println("The element "+Search+" is found at index "+i);
39+
break;
40+
41+
}
42+
}
43+
44+
if(!flag){
45+
System.out.println("Element not found in array...!");
46+
}
47+
48+
}
49+
}
50+

3.Array/PracticeCodes/Program12.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Program 11 : Write a program which takes in 10 values and
3+
creates another array which has cubes of the values and prints it.
4+
*/
5+
6+
package PracticeCodes;
7+
8+
import java.io.*;
9+
10+
public class Program12 {
11+
12+
public static void main(String[] args) throws IOException {
13+
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
16+
System.out.println("Enter the size of array : ");
17+
int size = Integer.parseInt(br.readLine());
18+
19+
int[] arr = new int[size];
20+
int[] cube = new int[size];
21+
22+
System.out.println("Enter the element of array : ");
23+
for (int i = 0; i < size; i++) {
24+
25+
arr[i] = Integer.parseInt(br.readLine());
26+
cube[i] = arr[i] * arr[i] * arr[i];
27+
}
28+
29+
System.out.println("Cube Array : ");
30+
for (int i = 0; i < size; i++) {
31+
32+
System.out.println(cube[i]);
33+
}
34+
35+
}
36+
}

3.Array/PracticeCodes/Program13.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
/*
3+
Program 12 : Write a program to take in 10 values and
4+
print only those numbers which are palindrome.
5+
*/
6+
7+
8+
package PracticeCodes;
9+
10+
import java.io.*;
11+
12+
public class Program13 {
13+
14+
public static void main(String[] args) throws IOException {
15+
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
18+
System.out.println("Enter the size of array : ");
19+
int size = Integer.parseInt(br.readLine());
20+
21+
int[] a = new int[size];
22+
23+
System.out.println("Enter the element of array : ");
24+
for (int i = 0; i < size; i++) {
25+
26+
a[i] = Integer.parseInt(br.readLine());
27+
}
28+
29+
System.out.println("The palindrome numbers are: ");
30+
for(int i=0;i<a.length;i++)
31+
{
32+
int num = a[i];
33+
int pal = 0;
34+
35+
while(num!=0)
36+
{
37+
int rem = num % 10;
38+
pal = pal * 10 +rem;
39+
40+
num /=10;
41+
42+
}
43+
44+
if(pal == a[i]){
45+
46+
System.out.print(a[i]+" ");
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)