Skip to content

Commit f778724

Browse files
authored
Merge pull request #3 from gitaman8481/gitaman8481-patch-3
Add files via upload
2 parents 6209948 + 0d652f3 commit f778724

Some content is hidden

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

62 files changed

+1819
-997
lines changed

arrays/BasicArrays.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +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-
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 & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +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-
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+

basics/ControlStatements.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +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-
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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
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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +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-
}
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 & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +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-
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+

0 commit comments

Comments
 (0)