Skip to content

Commit ed0ef1c

Browse files
committed
new folders added for program
0 parents  commit ed0ef1c

Some content is hidden

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

46 files changed

+1012
-0
lines changed

CollectionFramework/List.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package CollectionFramework;
2+
3+
import java.util.LinkedList;
4+
public class List{
5+
public static void main(String[] args) {
6+
7+
LinkedList<String> ll = new LinkedList<>();
8+
9+
ll.add("Aman");
10+
ll.add("Soni");
11+
ll.add(1, "Kumar");
12+
System.out.println(ll);
13+
}
14+
}

arrays/BasicArrays.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package arrays;
2+
3+
import java.io.*;
4+
5+
public class BasicArrays {
6+
7+
public static void main(String[] args) {
8+
9+
int a[];
10+
a = new int[5];
11+
12+
try {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
for(int i=0;i<5;i++) {
15+
int j=i+1;
16+
System.out.println(" Enter element no." +j);
17+
String s = br.readLine();
18+
a[i] = Integer.parseInt(s);
19+
}
20+
for(int i=0;i<5;i++) {
21+
System.out.println("arr["+i+"]="+a[i]);
22+
}
23+
}
24+
25+
catch(Exception e) {
26+
System.out.println(""+e);
27+
}
28+
}
29+
}
30+
31+
32+
33+

arrays/FIndDublicate.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package arrays;
2+
3+
public class FIndDublicate {
4+
// Implementing an array as a HashMap for finding duplicate elements
5+
void printRepeating(int m[],int size) {
6+
7+
int i;
8+
System.out.print("The repeating elements are:");
9+
10+
for(i=0;i<size;i++) {
11+
12+
// using Math.abs() function to find the duplicate element in HashMap.
13+
14+
if(m[Math.abs(m[i])]>=0) m[Math.abs(m[i])] = -m[Math.abs(m[i])];
15+
else System.out.print(Math.abs(m[i]) + " ");
16+
}
17+
}
18+
19+
//Driver Method
20+
public static void main(String[] args) {
21+
22+
FIndDublicate dublicate= new FIndDublicate(); // Making an object of FindDuplicate class
23+
24+
int m[] = {1,2,3,1,3,6,6}; // Putting or declare values in or to array
25+
int m_size = m.length; // variables which store size or length of array
26+
27+
dublicate.printRepeating(m,m_size); // calling above function to pass value in it to print repeating elements
28+
29+
}
30+
31+
}
32+

arrays/package-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package arrays;

basics/ControlStatements.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package basics;
2+
// public class to implement or for run the code
3+
public class ControlStatements {
4+
5+
public static void main(String[] args) {
6+
// for loop to implement switch case statement
7+
for(int i =0;i<9;i++){
8+
// switch controle statement
9+
switch(i) {
10+
// case1
11+
case 1:
12+
System.out.println(" i is zero.");
13+
break; //break statement
14+
//case2
15+
case 2:
16+
System.out.println(" i is one.");
17+
break;
18+
//case3
19+
case 3:
20+
System.out.println(" i is zero.");
21+
break;
22+
default: //default statement
23+
System.out.println(" i is greater than 3.");
24+
25+
}
26+
27+
}
28+
}
29+
}
30+
31+

basics/DoWhileLoop.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package basics;
2+
3+
public class DoWhileLoop {
4+
//method inside which do while loop will occur
5+
public static void main(String[] args) {
6+
7+
int n = 10;
8+
//do while loop's do block
9+
// must executes atleast once
10+
do {
11+
System.out.println(" tick " +n);
12+
n--;
13+
}while(n>0);// do while loop's while block
14+
} // end of main method
15+
}// end of class

basics/Operators.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package basics;
2+
3+
public class Operators {
4+
5+
public static void main(String[] args) {
6+
int a = 7,b= 6;
7+
int c = a*b; //* (multiplication) operator
8+
int d = a+b; // + addition operator
9+
int e = a/b; // - substration operator
10+
int f = a%b; // % modulus operator
11+
int g = a^b; // ^ power operator
12+
long h = b^a;
13+
System.out.println(c + " " + d + " " + e + " " + f + " " + g + " " + h);
14+
15+
}
16+
17+
}

basics/Treedatastructure.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package basics;
2+
3+
// a node class
4+
class Node{
5+
int key ;
6+
Node left,right;
7+
public Node(int item) {
8+
key = item;
9+
left = right = null;
10+
}
11+
}
12+
13+
class Treedatastructure{
14+
// Root of Binary Tree
15+
Node root;
16+
17+
// Constructors
18+
Treedatastructure(int key)
19+
{
20+
root = new Node(key);
21+
}
22+
23+
Treedatastructure()
24+
{
25+
root = null;
26+
}
27+
28+
public static void main(String[] args)
29+
{
30+
Treedatastructure tree = new Treedatastructure();
31+
32+
/*create root*/
33+
tree.root = new Node(1);
34+
35+
/* following is the tree after above statement
36+
37+
1
38+
/ \
39+
null null */
40+
41+
tree.root.left = new Node(2);
42+
tree.root.right = new Node(3);
43+
44+
/* 2 and 3 become left and right children of 1
45+
1
46+
/ \
47+
2 3
48+
/ \ / \
49+
null null null null */
50+
51+
52+
tree.root.left.left = new Node(4);
53+
/* 4 becomes left child of 2
54+
1
55+
/ \
56+
2 3
57+
/ \ / \
58+
4 null null null
59+
/ \
60+
null null
61+
*/
62+
63+
}}
64+
65+

basics/VariablesandDataTypes.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package basics;
2+
3+
public class VariablesandDataTypes {
4+
5+
public static void main(String[] args) {
6+
7+
int age = 18; // integer data type
8+
String name = "Aman"; // String data type
9+
long number = 7023; // long data type
10+
String address ="Behind Fort";
11+
System.out.println(age + " " + name + " " + number + " " + address);
12+
13+
}
14+
15+
}

basics/WhileLoop.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package basics;
2+
3+
public class WhileLoop {
4+
5+
public static void main(String[] args) {
6+
7+
int n = 5;
8+
// while loop block
9+
while(n>0) {
10+
System.out.println(" tick " + n);
11+
n--; // post substraction operator
12+
}
13+
14+
}
15+
16+
}

0 commit comments

Comments
 (0)