Skip to content

Commit e0ce817

Browse files
main
1 parent 983c637 commit e0ce817

28 files changed

+1210
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
/*
3+
4+
Q1
5+
write a program to print the following pattern
6+
D4 C3 B2 A1
7+
A1 B2 C3 D4
8+
D4 C3 B2 A1
9+
A1 B2 C3 D4
10+
11+
12+
*/
13+
14+
15+
16+
package NestedLoop.Assignment.Assignment05;
17+
18+
import java.io.BufferedReader;
19+
import java.io.IOException;
20+
import java.io.InputStreamReader;
21+
22+
public class program1 {
23+
public static void main(String[] args)throws IOException {
24+
25+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
26+
27+
System.out.println("Enter the number of rows: ");
28+
29+
int row = Integer.parseInt(br.readLine());
30+
31+
char ch = (char)(64+row);
32+
int num = row;
33+
34+
for(int i=1;i<=row;i++){
35+
36+
for(int j=1;j<=row;j++){
37+
38+
if(i%2==1){
39+
System.out.print(ch);
40+
System.out.print(num+" ");
41+
42+
ch--;
43+
num--;
44+
}
45+
46+
else{
47+
48+
ch++;
49+
num++;
50+
System.out.print(ch);
51+
System.out.print(num+" ");
52+
53+
}
54+
55+
}
56+
System.out.println();
57+
}
58+
59+
60+
}
61+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
/*
3+
4+
Q10
5+
write a program to print a series of prime numbers from entered range. ( Take a start and end
6+
number from a user )
7+
Perform dry run at least from 10 to 20 ...
8+
Input:-
9+
Enter starting number: 10
10+
Enter ending number: 100
11+
Output:-
12+
Series = 11 13 17 19 ..... 89 97
13+
14+
*/
15+
16+
17+
18+
package NestedLoop.Assignment.Assignment05;
19+
20+
import java.io.BufferedReader;
21+
import java.io.InputStreamReader;
22+
23+
24+
public class program10 {
25+
26+
public static void main(String[] args)throws Exception {
27+
28+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
29+
30+
System.out.println("Enter the start and end: ");
31+
32+
int start = Integer.parseInt(br.readLine());
33+
int end = Integer.parseInt(br.readLine());
34+
35+
for(int i=start;i<=end;i++){
36+
int count=0;
37+
for(int j=2;j<=Math.sqrt(i);j++){
38+
39+
if(i % j==0){
40+
count++;
41+
}
42+
}
43+
44+
if(count==0){
45+
System.out.print(i+" ");
46+
}
47+
}
48+
}
49+
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
/*
3+
Q2
4+
write a program to print the following pattern
5+
# = = = =
6+
= # = = =
7+
= = # = =
8+
= = = # =
9+
= = = = #
10+
11+
*/
12+
13+
package NestedLoop.Assignment.Assignment05;
14+
15+
import java.io.BufferedReader;
16+
import java.io.IOException;
17+
import java.io.InputStreamReader;
18+
19+
20+
public class program2 {
21+
public static void main(String[] args)throws IOException {
22+
23+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
24+
25+
System.out.println("Enter the number of rows: ");
26+
27+
int row = Integer.parseInt(br.readLine());
28+
29+
30+
for(int i=1;i<=row;i++){
31+
32+
for(int j=1;j<=row;j++){
33+
34+
if(i==j){
35+
System.out.print("#"+" ");
36+
}
37+
38+
else{
39+
System.out.print("="+" ");
40+
}
41+
42+
}
43+
44+
System.out.println();
45+
46+
}
47+
}
48+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
3+
/*
4+
write a program to print the following pattern
5+
5 4 3 2 1
6+
8 6 4 2
7+
9 6 3
8+
8 4
9+
5
10+
*/
11+
12+
13+
14+
package NestedLoop.Assignment.Assignment05;
15+
16+
import java.io.BufferedReader;
17+
import java.io.IOException;
18+
import java.io.InputStreamReader;
19+
20+
21+
public class program3 {
22+
public static void main(String[] args)throws IOException {
23+
24+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
25+
26+
System.out.println("Enter the number of rows: ");
27+
28+
int row = Integer.parseInt(br.readLine());
29+
30+
int num = row;
31+
for(int i=1;i<=row;i++){
32+
33+
int num1 = num*i;
34+
35+
for(int j=1;j<=row-i+1;j++){
36+
37+
System.out.print(num1+" ");
38+
num1 -=i;
39+
}
40+
41+
num--;
42+
System.out.println();
43+
44+
}
45+
}
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/*
3+
Q4
4+
WAP to print all even numbers in reverse order and odd numbers in the standard way. Both separately.
5+
Within a range. Take the start and end from user
6+
Input: Enter start number - 2
7+
Enter End number - 9
8+
Output:
9+
8 6 4 2
10+
3 5 7 9
11+
*/
12+
13+
package NestedLoop.Assignment.Assignment05;
14+
15+
import java.io.BufferedReader;
16+
import java.io.IOException;
17+
import java.io.InputStreamReader;
18+
19+
public class program4 {
20+
public static void main(String[] args) throws IOException {
21+
22+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
23+
System.out.println("Enter Start and End of range");
24+
int start = Integer.parseInt(br.readLine());
25+
int end = Integer.parseInt(br.readLine());
26+
27+
28+
System.out.print("Even Num: ");
29+
for (int i = end; i >= start; i--) {
30+
if (i % 2 == 0)
31+
System.out.print(i + " ");
32+
33+
}
34+
35+
System.out.println();
36+
System.out.print("Odd Num: ");
37+
for (int i = start; i <= end; i++) {
38+
if (i % 2 == 1) {
39+
System.out.print(i + " ");
40+
}
41+
}
42+
System.out.println();
43+
}
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
/*
3+
4+
Q5
5+
write a program to print the following pattern
6+
Row =4
7+
0
8+
1 1
9+
2 3 5
10+
8 13 21 34
11+
12+
*/
13+
14+
package NestedLoop.Assignment.Assignment05;
15+
16+
import java.io.BufferedReader;
17+
import java.io.IOException;
18+
import java.io.InputStreamReader;
19+
20+
public class program5 {
21+
public static void main(String[] args) throws IOException {
22+
23+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
24+
25+
System.out.println("Enter the number of rows: ");
26+
27+
int row = Integer.parseInt(br.readLine());
28+
29+
int n1 = 0;
30+
int n2 = 1;
31+
int n3;
32+
for (int i = 1; i <= row; i++) {
33+
34+
for (int j = 1; j <= i; j++) {
35+
n3 = n1 + n2;
36+
System.out.print(n1 + " ");
37+
n1 = n2;
38+
n2 = n3;
39+
}
40+
41+
System.out.println();
42+
43+
}
44+
}
45+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
/*
3+
Q6
4+
Write a program, and take two characters if these characters are equal then print them as it is but if
5+
they are unequal then print their difference.
6+
{Note: Consider Positional Difference Not ASCIIs}
7+
8+
Input: a p
9+
Output: The difference between a and p is 15
10+
*/
11+
12+
13+
14+
package NestedLoop.Assignment.Assignment05;
15+
16+
import java.io.BufferedReader;
17+
import java.io.IOException;
18+
import java.io.InputStreamReader;
19+
20+
public class program6 {
21+
public static void main(String[] args)throws IOException {
22+
23+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
24+
25+
System.out.println("Enter the character: ");
26+
char ch1 = (char)br.read();
27+
br.skip(2);
28+
29+
System.out.println("Enter the character: ");
30+
char ch2 = (char)br.read();
31+
32+
if(ch1==ch2){
33+
System.out.println(ch1+" is equal to "+ch2);
34+
}
35+
36+
else{
37+
System.out.println(ch2-ch1);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)