Skip to content

Commit dd13129

Browse files
Initial Upload
The main upload to the repo
1 parent 8a157cb commit dd13129

Some content is hidden

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

54 files changed

+1701
-0
lines changed

ArrayList_Basics.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.util.ArrayList;
2+
import java.util.Scanner;
3+
4+
public class ArrayList_Basics {
5+
static Scanner sn = new Scanner(System.in);
6+
7+
static void display(ArrayList<Integer> arrl) {
8+
if (arrl.isEmpty())
9+
return;
10+
11+
System.out.println("Array : " + arrl);
12+
}
13+
14+
static boolean Search(ArrayList<Integer> arrl) {
15+
if (arrl.isEmpty())
16+
return false;
17+
18+
System.out.println("Enter the value to be searched : ");
19+
int x = sn.nextInt();
20+
return arrl.contains(x);
21+
}
22+
23+
static void remove(ArrayList<Integer> arrl, int index) {
24+
if (arrl.isEmpty())
25+
return;
26+
27+
if (arrl.contains(arrl.get(index)))
28+
arrl.remove(index);
29+
30+
else {
31+
System.out.println("Confirm Input Element");
32+
return;
33+
}
34+
35+
}
36+
37+
}

Arrays_Basics.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import java.util.Scanner;
2+
3+
public class Arrays_Basics {
4+
5+
public static void main(String[] args) {
6+
// TODO Auto-generated method stub
7+
8+
// set of multiple objects
9+
int[] marks = { 100, 65, 78, 21, 77 };
10+
11+
for (int i = 0; i < marks.length; i++) {
12+
System.out.print(i + "\t");
13+
System.out.println(marks[i]);
14+
}
15+
16+
for (int i = marks.length - 1; i >= 0; i--) {
17+
System.out.print(i + "\t");
18+
System.out.println(marks[i]);
19+
}
20+
21+
for (int i : marks) {
22+
System.out.print(i + "\t");
23+
}
24+
25+
int[][] a = new int[2][3];
26+
a[0][0] = 101;
27+
a[0][1] = 102;
28+
a[0][2] = 103;
29+
a[1][0] = 201;
30+
a[1][1] = 202;
31+
a[1][2] = 203;
32+
33+
for (int i = 0; i < a.length; i++) {
34+
for (int j = 0; j < a[i].length; j++) {
35+
System.out.print(a[i][j] + "\t");
36+
}
37+
38+
}
39+
40+
// 1.
41+
float[] fl = { 5.78f, 67, 33.8f, 22, 90.9f };
42+
float f = 0;
43+
for (int i = 0; i < fl.length; i++) {
44+
f += fl[i];
45+
}
46+
System.out.println(f);
47+
48+
// 2.
49+
Scanner sn = new Scanner(System.in);
50+
double n = sn.nextDouble();
51+
double[] ab = { 78, 69.887, 56.75, 76.83, 93.5, 63.42, 65.2 };
52+
for (int i = 0; i < ab.length; i++) {
53+
if (ab[i] != n) {
54+
continue;
55+
} else {
56+
System.out.println("location is : " + i);
57+
break;
58+
}
59+
}
60+
sn.close();
61+
62+
// 3.
63+
double[] ac = { 78, 69.8, 56.75, 76.8, 93.5, 63.42, 65.2, 98.5 };
64+
double s = 0;
65+
for (int i = 0; i < ac.length; i++) {
66+
s += ac[i];
67+
}
68+
s /= a.length;
69+
System.out.println(s);
70+
71+
// 4.
72+
double[][] m1 = new double[2][3];
73+
double[][] m2 = new double[2][3];
74+
75+
for (int i = 0; i < m1.length; i++) {
76+
for (int j = 0; j < m1[i].length; j++) {
77+
m1[i][j] = sn.nextDouble();
78+
m2[i][j] = sn.nextDouble();
79+
}
80+
}
81+
sn.close();
82+
83+
// 5. The system will swear at you if you execute this command
84+
String[] arr = { "u", " ", "k", "c", "u", "f" };
85+
for (int i = arr.length - 1; i >= 0; i--) {
86+
System.out.print(arr[i]);
87+
}
88+
// told you so
89+
90+
// 6. , 7.
91+
int[] ar = { 76, 65, 78, 21, 77 };
92+
int max = 0;
93+
int min = Integer.MAX_VALUE;
94+
for (int i = 0; i < ar.length; i++) {
95+
max = Math.max(ar[i], max);
96+
min = Math.min(ar[i], min);
97+
}
98+
System.out.println("Maximum = " + max);
99+
System.out.println("Minimum = " + min);
100+
101+
}
102+
}

Basic_Datacleaning.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.io.*;
2+
3+
public class Basic_Datacleaning {
4+
5+
public static void main(String[] args) {
6+
// TODO Auto-generated method stub
7+
try {
8+
FileReader fr = new FileReader("C:\\Users\\hp\\Downloads\\[CSE3141] Attendance - Sheet1 (1).csv");
9+
FileWriter fw = new FileWriter("C:\\Users\\hp\\Desktop\\Untitled.txt");
10+
BufferedReader br = new BufferedReader(fr);
11+
BufferedWriter bw = new BufferedWriter(fw);
12+
13+
String line = br.readLine();
14+
while (line != null) {
15+
String ans[] = line.split(",+", 0);
16+
String res = ans[0];
17+
for (int i = 1; i < ans.length - 2; i++) {
18+
res = res + "," + ans[i];
19+
}
20+
System.out.println(res);
21+
bw.write(res + "\n");
22+
line = br.readLine();
23+
}
24+
fr.close();
25+
bw.close();
26+
// System.out.println("File Copied");
27+
} catch (IOException e) {
28+
System.out.println("Error");
29+
e.printStackTrace();
30+
}
31+
}
32+
33+
}

Basic_FILE_HADLING.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.*;
2+
3+
public class Basic_FILE_HADLING {
4+
public static void main(String args[]) throws IOException {
5+
File fileName = new File("C:\\Users\\hp\\Downloads\\[CSE3141] Attendance - Sheet1 (1).csv");
6+
7+
FileInputStream inFile = new FileInputStream("C:\\Users\\hp\\Downloads\\[CSE3141] Attendance - Sheet1 (1).csv");
8+
int fileLength = (int) fileName.length();
9+
10+
byte Bytes[] = new byte[fileLength];
11+
12+
System.out.println("File size is: " + inFile.read(Bytes));
13+
14+
String file1 = new String(Bytes);
15+
System.out.println("File content is:\n" + file1);
16+
17+
FileOutputStream outFile = new FileOutputStream("C:\\Users\\hp\\Desktop\\Untitled.txt");
18+
19+
for (int i = 0; i < fileLength; i++) {
20+
outFile.write(Bytes[i]);
21+
}
22+
23+
System.out.println("File copied.");
24+
// close files
25+
inFile.close();
26+
outFile.close();
27+
}
28+
}

Binary_Search_in_Array.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class Binary_Search_in_Array {
2+
static int binsch(int arr[], int l, int r, int x) {
3+
4+
if (r >= 1) {
5+
6+
int m = l + (r - 1) / 2;
7+
8+
if (x == arr[m])
9+
return m;
10+
11+
if (x < arr[m])
12+
return binsch(arr, l, m - 1, x);
13+
14+
return binsch(arr, m + 1, r, x);
15+
}
16+
17+
return -1;
18+
}
19+
20+
public static void main(String args[]) {
21+
int arr[] = { 2, 3, 4, 10, 40 };
22+
int n = arr.length;
23+
int x = 10;
24+
int result = binsch(arr, 0, n - 1, x);
25+
26+
if (result == -1)
27+
System.out.println("Element is not present in array");
28+
29+
else
30+
System.out.println("Element is present at index : " + result);
31+
}
32+
}

Decimal_to_Binary_ONE_LINER.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Decimal_to_Binary_ONE_LINER {
2+
3+
public static void main(String[] args) {
4+
5+
System.out.println(Integer.toBinaryString(20));
6+
}
7+
}

Decimal_to_Binary_STACK.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.Stack;
2+
3+
public class Decimal_to_Binary_STACK {
4+
static void stackBin(int x) {
5+
Stack<Integer> s = new Stack<>();
6+
7+
while (x > 0) {
8+
int r = x % 2;
9+
s.push(r);
10+
x /= 2;
11+
}
12+
13+
while (!s.isEmpty())
14+
System.out.print(s.pop());
15+
}
16+
17+
public static void main(String[] args) {
18+
stackBin(29);
19+
}
20+
}

Distance_TwoPoints.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.util.Scanner;
2+
3+
class Point {
4+
float x, y;
5+
6+
void setPoint(float x1, float y1) {
7+
x = x1;
8+
y = y1;
9+
}
10+
11+
void showPoint() {
12+
System.out.println("(" + x + "," + y + ")");
13+
}
14+
15+
double findDistance(Point p) {
16+
double f = Math.sqrt((Math.pow((p.x - x), 2)) + (Math.pow((p.y - y), 2)));
17+
return f;
18+
}
19+
}
20+
21+
class Distance_TwoPoints {
22+
23+
public static void main(String[] args) {
24+
// TODO Auto-generated method stub
25+
Scanner in = new Scanner(System.in);
26+
27+
Point a = new Point();
28+
System.out.println("Enter the coordinates for point 1:");
29+
30+
float k = in.nextFloat();
31+
float l = in.nextFloat();
32+
a.setPoint(k, l);
33+
34+
System.out.print("Point 1 is:");
35+
a.showPoint();
36+
37+
Point b = new Point();
38+
System.out.println("Enter the coordinates for point 2:");
39+
40+
int k1 = in.nextInt();
41+
int l1 = in.nextInt();
42+
b.setPoint(k1, l1);
43+
44+
System.out.print("Point 2 is:");
45+
b.showPoint();
46+
47+
double d = a.findDistance(b);
48+
System.out.print("Distance between point 1 and point 2 is approximately: " + d);
49+
in.close();
50+
51+
}
52+
53+
}

GCD_of_TWO_numbers.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class GCD_of_TWO_numbers {
2+
3+
static int Gcd(int a, int b) {
4+
5+
if (b > a)
6+
return Gcd(b, a);
7+
8+
if (a % b == 0)
9+
return b;
10+
11+
if (a == 0)
12+
return b;
13+
if (b == 0)
14+
return a;
15+
16+
return Gcd(b, a % b);
17+
}
18+
19+
public static void main(String[] args) {
20+
System.out.println(Gcd(81, 108));
21+
}
22+
}

Graph_BFS_Traversal.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.ArrayDeque;
2+
3+
public class Graph_BFS_Traversal {
4+
5+
static void TraversalBFS(int gra[][]) {
6+
7+
ArrayDeque<Integer> ad = new ArrayDeque<>();
8+
boolean visited[] = new boolean[gra.length];
9+
10+
ad.add(0);
11+
visited[0] = true;
12+
13+
while (!ad.isEmpty()) {
14+
15+
int u = ad.poll();
16+
System.out.print(u + " ");
17+
18+
for (int j = 0; j < gra[u].length; j++) {
19+
20+
if (gra[u][j] == 1 && !visited[j]) {
21+
ad.add(j);
22+
visited[j] = true;
23+
}
24+
}
25+
}
26+
}
27+
28+
public static void main(String[] args) {
29+
// TODO Auto-generated method stub
30+
31+
}
32+
33+
}

0 commit comments

Comments
 (0)