Skip to content

Commit 6aa90a0

Browse files
Add files via upload
1 parent a1417b5 commit 6aa90a0

File tree

9 files changed

+418
-0
lines changed

9 files changed

+418
-0
lines changed

GuessGame.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.Random;
2+
import java.util.Scanner;
3+
4+
public class GuessGame {
5+
public static void main(String[] args) {
6+
Random rand = new Random();
7+
Scanner sc = new Scanner(System.in);
8+
9+
int number = rand.nextInt(100) + 1;
10+
int guess;
11+
12+
System.out.println("Guess a number between 1 and 100:");
13+
14+
do {
15+
guess = sc.nextInt();
16+
if (guess > number) {
17+
System.out.println("Too high! Try again:");
18+
} else if (guess < number) {
19+
System.out.println("Too low! Try again:");
20+
} else {
21+
System.out.println("Correct! The number was " + number);
22+
}
23+
} while (guess != number);
24+
}
25+
}
26+
27+
28+

LineCoding.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import java.util.Scanner;
2+
3+
public class LineCoding {
4+
5+
// Function for Unipolar NRZ
6+
static void unipolarNRZ(int[] data) {
7+
System.out.println("Unipolar NRZ Encoding:");
8+
for (int bit : data) {
9+
if (bit == 1) System.out.print("[+1] ");
10+
else System.out.print("[0] ");
11+
}
12+
System.out.println();
13+
}
14+
15+
// Function for Polar NRZ
16+
static void polarNRZ(int[] data) {
17+
System.out.println("Polar NRZ Encoding:");
18+
for (int bit : data) {
19+
if (bit == 1) System.out.print("[+1] ");
20+
else System.out.print("[-1] ");
21+
}
22+
System.out.println();
23+
}
24+
25+
// Function for Manchester Encoding
26+
static void manchester(int[] data) {
27+
System.out.println("Manchester Encoding:");
28+
for (int bit : data) {
29+
if (bit == 1) System.out.print("[+1, -1] ");
30+
else System.out.print("[-1, +1] ");
31+
}
32+
System.out.println();
33+
}
34+
35+
// Function for Differential Manchester Encoding
36+
static void differentialManchester(int[] data) {
37+
System.out.println("Differential Manchester Encoding:");
38+
int current = 1; // Assume starting high (+1)
39+
for (int bit : data) {
40+
if (bit == 1) {
41+
// Transition at beginning
42+
current = -current;
43+
}
44+
// Always transition at mid-bit
45+
if (current == 1) System.out.print("[+1, -1] ");
46+
else System.out.print("[-1, +1] ");
47+
current = -current; // flip for next bit
48+
}
49+
System.out.println();
50+
}
51+
52+
public static void main(String[] args) {
53+
try (Scanner sc = new Scanner(System.in)) {
54+
// Step 1: Input number of bits
55+
System.out.print("Enter the number of bits in the data: ");
56+
int n = sc.nextInt();
57+
int[] data = new int[n];
58+
59+
// Step 2: Input binary sequence
60+
System.out.println("Enter the binary data bits (0s and 1s): ");
61+
for (int i = 0; i < n; i++) {
62+
data[i] = sc.nextInt();
63+
if (data[i] != 0 && data[i] != 1) {
64+
System.out.println("Invalid input. Only 0s and 1s allowed.");
65+
return;
66+
}
67+
}
68+
69+
// Step 3: Choose encoding method
70+
System.out.println("\nChoose a line coding technique:");
71+
System.out.println("1. Unipolar NRZ");
72+
System.out.println("2. Polar NRZ");
73+
System.out.println("3. Manchester");
74+
System.out.println("4. Differential Manchester");
75+
System.out.print("Enter your choice (1-4): ");
76+
int choice = sc.nextInt();
77+
78+
// Step 4: Call respective function
79+
switch (choice) {
80+
case 1 -> unipolarNRZ(data);
81+
case 2 -> polarNRZ(data);
82+
case 3 -> manchester(data);
83+
case 4 -> differentialManchester(data);
84+
default -> System.out.println("Invalid choice. Please select between 1 and 4.");
85+
}
86+
87+
sc.close();
88+
}
89+
}
90+
}

java.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import java.util.Scanner;
2+
3+
public class java {
4+
5+
public static void main(String[] args) {
6+
// Scanner sc = new Scanner(System.in);
7+
// System.out.println("Enter a number:");
8+
// int num = sc.nextInt();
9+
// if(num%2==0){
10+
// System.out.println("The given number is even!");
11+
12+
// }
13+
// else{
14+
// System.out.println("The given number is odd!");
15+
// }
16+
17+
18+
19+
// Scanner sc = new Scanner(System.in);
20+
21+
// String opertations--------------------------------------------------
22+
23+
// Scanner sc = new Scanner(System.in);
24+
// System.out.println("Enter a string:");
25+
// String s = sc.nextLine();
26+
27+
// System.out.println("Length of string:"+s.length());
28+
// System.out.println(s.toLowerCase());
29+
// System.out.println(s.toUpperCase());
30+
31+
// //counting number of vowels in a string
32+
33+
34+
// int vowels = 0;
35+
// for(int i=0; i<s.length(); i++){
36+
// char ch = s.charAt(i);
37+
// if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U'){
38+
// vowels++;
39+
40+
// }
41+
42+
// }
43+
// System.out.println("Number of vowels in the string:"+vowels);
44+
45+
// ----------------------------------------------------------
46+
47+
// 1. String
48+
49+
50+
// Scanner sc = new Scanner(System.in);
51+
// String name;
52+
// System.out.print("Enter your name: ");
53+
// name = sc.nextLine();
54+
// System.out.println("Hello, " + name);
55+
// System.out.println("Length = " + name.length());
56+
// System.out.println("Upper case = " + name.toUpperCase());
57+
// System.out.println("Lower case = " + name.toLowerCase());
58+
59+
60+
// // 2. Break
61+
// for (int i = 1; i <= 5; i++) {
62+
// if (i == 3) break; // Exits loop
63+
// System.out.println("i = " + i);
64+
// }
65+
66+
// // 3. Continue
67+
// for (int i = 1; i <= 5; i++) {
68+
// if (i == 3) continue; // Skips the rest of the loop when i is 3
69+
// System.out.println("i = " + i);
70+
71+
// }
72+
// 4. Return
73+
74+
// System.out.println("Before return");
75+
// if (true) return;
76+
// System.out.println("After return");
77+
78+
79+
// 5. Reverse a number
80+
81+
82+
try (
83+
Scanner scanner = new Scanner(System.in)) {
84+
System.out.print("Enter a number: ");
85+
int number = scanner.nextInt();
86+
int reversed = 0;
87+
while (number > 0) {
88+
int digit = number % 10;
89+
reversed = reversed * 10 + digit;
90+
number /= 10;
91+
}
92+
System.out.println("Reversed number: " + reversed);
93+
}
94+
// 6. While loop
95+
96+
int i = 1;
97+
while (i <= 5) {
98+
System.out.println("While loop count: " + i);
99+
i++;
100+
}
101+
102+
103+
int count = 1;
104+
do {
105+
System.out.println("Do-While count: " + count);
106+
count++;
107+
} while (count <= 5);
108+
}
109+
110+
111+
}
112+
113+
114+
115+
116+

java1.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.Scanner;
2+
public class java1 {
3+
public static void main(String[] args) {
4+
Scanner sc = new Scanner(System.in);
5+
System.out.print("Enter a number: ");
6+
int n = sc.nextInt();
7+
8+
boolean isPrime = true;
9+
if (n <= 1) isPrime = false;
10+
else {
11+
for (int i = 2; i <= Math.sqrt(n); i++) {
12+
if (n % i == 0) {
13+
isPrime = false;
14+
break;
15+
}
16+
}
17+
}
18+
19+
System.out.println(n + (isPrime ? " is Prime" : " is Not Prime"));
20+
}
21+
}
22+
23+
24+

java_program.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
import java.util.Arrays;
3+
import java.util.Scanner;
4+
public class java_program {
5+
public static void main(String[] args){
6+
System.out.println("First java program");
7+
System.out.println("Hello java");
8+
System.out.println("Java is one of the programming language");
9+
int a = 5 , b = 10;
10+
System.out.println("addition:"+ (a+b));
11+
System.out.println("sub:"+(a-b));
12+
System.out.println("mul:"+(a*b));
13+
System.out.println("div:"+(a/b));
14+
System.out.println("modulus:"+(a%b));
15+
try (Scanner sc = new Scanner(System.in)) {
16+
System.out.println("Enter first no:");
17+
int num1 = sc.nextInt();
18+
System.out.println("Enter second no:");
19+
int num2 = sc.nextInt();
20+
System.out.println("Addition:"+(num1+num2));
21+
System.out.println("multiplication:"+(num1*num2));
22+
System.out.println("Modulus:"+(num1%num2));
23+
System.out.println("Subtraction:"+(num1-num2));
24+
System.out.println("Division:"+(num1/num2));
25+
if (num2!=0) {
26+
double division = (double) num1 / num2;
27+
System.out.println("Division:" + division);
28+
} else {
29+
System.out.println("Division by zero is not allowed.");
30+
}
31+
32+
if(num2!=0){
33+
double modulo = (double) num1 % num2;
34+
System.out.println("Modulo:" + modulo);
35+
} else {
36+
37+
System.out.println("Modulus by zero is not allowed.");
38+
}
39+
40+
int []nums={1,2,3};
41+
for(int n : nums){
42+
System.out.println( n);
43+
}
44+
45+
int [] [] num = {{1,2},{5,6}};
46+
System.out.println(num[0][0]);
47+
System.out.println(num[0][1]);
48+
System.out.println(num[1][0]);
49+
System.out.println(num[1][1]);
50+
51+
System.out.println("Enter the size of the array:");
52+
int size = sc.nextInt();
53+
int[] userNums = new int[size];
54+
System.out.println("Enter"+ size +"numbers");
55+
for(int i = 0; i<size;i++) userNums[i]=sc.nextInt();
56+
System.out.println("Enetr array elements:"+Arrays.toString(userNums));
57+
int sum =0;
58+
for(int n:userNums) sum+=n;
59+
System.out.println("Sum of array elements:"+sum);
60+
}
61+
62+
63+
64+
65+
66+
}
67+
68+
}
69+
70+
71+
72+

matrixaddition.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class matrixaddition {
2+
public static void main(String[] args) {
3+
int a[][]={{5,6,4},{15,8,5},{8,3,9}};
4+
int b[][]={{9,8,2},{6,5,6},{1,5,10}};
5+
int c[][]=new int[3][3];
6+
for(int i=0;i<3;i++){
7+
for(int j=0;j<3;j++){
8+
c[i][j]=a[i][j]+b[i][j];
9+
}
10+
}
11+
for(int i=0;i<3;i++){
12+
for(int j=0;j<3;j++){
13+
System.out.print(c[i][j]+" ");
14+
}
15+
System.out.println();
16+
}
17+
}
18+
}

matrixmultiplication.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class matrixmultiplication {
2+
public static void main(String[] args) {
3+
int a[][]={{1,2,3},{4,5,6},{7,8,9}};
4+
int b[][]={{9,8,7},{6,5,4},{3,2,1}};
5+
int c[][]=new int[3][3];
6+
for(int i=0;i<3;i++){
7+
for(int j=0;j<3;j++){
8+
c[i][j]=0;
9+
for(int k=0;k<3;k++){
10+
c[i][j]+=a[i][k]*b[k][j];
11+
}
12+
}
13+
}
14+
for(int i=0;i<3;i++){
15+
for(int j=0;j<3;j++){
16+
System.out.print(c[i][j]+" ");
17+
}
18+
System.out.println();
19+
}
20+
}
21+
22+
23+
}

0 commit comments

Comments
 (0)