Skip to content

Commit 0c3cb07

Browse files
main
1 parent 51eb932 commit 0c3cb07

Some content is hidden

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

41 files changed

+1055
-207
lines changed

1.DataType/ClassCodes/program1.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ClassCodes;
2+
3+
public class program1 {
4+
public static void main(String[] args) {
5+
int age= 10;
6+
System.out.println("Age: "+age);
7+
8+
9+
}
10+
}

1.DataType/Program1.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ public static void main(String[] args){
99

1010
System.out.println(var1); //Error :
1111
System.out.println(var1);
12-
1312
}
1413
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
/*
3+
Program 10 : write a program to print a series of prime numbers from entered range. ( Take a start and end number
4+
from a user )
5+
Perform dry run at least from 10 to 20 ...
6+
Input:-
7+
Enter starting number: 10
8+
Enter ending number: 100
9+
Output:-
10+
Series = 11 13 17 19 ..... 89 97
11+
*/
12+
13+
package For.Assignment.Assignment07;
14+
import java.io.BufferedReader;
15+
import java.io.InputStreamReader;
16+
17+
public class program10 {
18+
public static void main(String[] args)throws Exception{
19+
20+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
21+
22+
System.out.println("Enter the start and end Number : ");
23+
int start = Integer.parseInt(br.readLine());
24+
int end = Integer.parseInt(br.readLine());
25+
26+
System.out.print("Output: Prime numbers between "+start+" and "+end+" are:");
27+
28+
for(int i=start;i<=end;i++)
29+
{
30+
int cnt=0;
31+
for(int j=1;j<=i;j++)
32+
{
33+
if(i % j==0)
34+
{
35+
cnt++;
36+
}
37+
38+
if(cnt>2)
39+
{
40+
break;
41+
}
42+
}
43+
if(cnt==2)
44+
{
45+
System.out.print(i+" ");
46+
}
47+
}
48+
}
49+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
/*
3+
Program 4 : WAP to print all even numbers in reverse order and odd numbers in the standard way. Both separately.
4+
Within a range. Take the start and end from user
5+
Input: Enter start number - 2
6+
Enter End number - 9
7+
Output:
8+
8 6 4 2
9+
3 5 7 9
10+
*/
11+
12+
13+
package For.Assignment.Assignment07;
14+
import java.io.BufferedReader;
15+
import java.io.InputStreamReader;
16+
17+
public class program3 {
18+
public static void main(String[] args)throws Exception {
19+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
20+
21+
System.out.println("Enter the starting of the number: ");
22+
int start = Integer.parseInt(br.readLine());
23+
24+
System.out.println("Enter the ending of the number: ");
25+
int end = Integer.parseInt(br.readLine());
26+
27+
System.out.println("Output:");
28+
29+
for(int i = end; i >= start;i--){
30+
31+
if(i % 2 == 0){
32+
33+
System.out.print(i + " ");
34+
}
35+
}
36+
System.out.println();
37+
for(int i = start; i <= end;i++){
38+
39+
if(i % 2 == 1){
40+
System.out.print(i + " ");
41+
}
42+
}
43+
}
44+
45+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/*
3+
Program 5 : write a program to print the following pattern
4+
Row =4
5+
0
6+
1 1
7+
2 3 5
8+
8 13 21 34
9+
USE THIS FOR LOOP STRICTLY for the outer loop
10+
Int row;
11+
Take the number of rows from user
12+
for(int i =1;i<=row;i++){
13+
14+
}
15+
*/
16+
17+
18+
package For.Assignment.Assignment07;
19+
import java.io.BufferedReader;
20+
import java.io.InputStreamReader;
21+
22+
public class program4 {
23+
public static void main(String[] args)throws Exception {
24+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
25+
26+
System.out.println("Enter the number of rows: ");
27+
int row = Integer.parseInt(br.readLine());
28+
int n1=0,n2=1,n3;
29+
30+
for(int i=1;i<=row;i++)
31+
{
32+
for(int j=1;j<=i;j++)
33+
{
34+
System.out.print(n1+" ");
35+
n3 = n1+n2;
36+
n1=n2;
37+
n2=n3;
38+
}
39+
System.out.println();
40+
}
41+
42+
}
43+
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
/*
3+
Prorgam 6 : Write a program, and take two characters if these characters are equal then print them as it is but if
4+
they are unequal then print their difference.
5+
{Note: Consider Positional Difference Not ASCIIs}
6+
7+
Input: a p
8+
Output: The difference between a and p is 15
9+
*/
10+
11+
12+
package For.Assignment.Assignment07;
13+
import java.io.BufferedReader;
14+
import java.io.InputStreamReader;
15+
16+
public class program5 {
17+
public static void main(String[] args)throws Exception {
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
20+
System.out.println("Enter the 1st character : ");
21+
char ch1 = (char)br.read();
22+
23+
br.skip(1);
24+
25+
System.out.println("Enter the 2nd character : ");
26+
char ch2 = (char)br.read();
27+
br.skip(1);
28+
29+
if(ch1==ch2)
30+
{
31+
System.out.println(ch1 + " & " + ch2 + " are equal" );
32+
}
33+
34+
else{
35+
36+
if(ch1 > ch2){
37+
38+
System.out.println("The difference between " + ch1 + " & " + ch2 + " is " + (ch1 - ch2));
39+
}
40+
else{
41+
42+
System.out.println("The difference between " + ch1 + " & " + ch2 + " is " + (ch2 - ch1));
43+
}
44+
}
45+
}
46+
47+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
/*
3+
Program 7 : write a program to print the following pattern
4+
Row =5;
5+
O
6+
14 13
7+
L K J
8+
9 8 7 6
9+
E D C B A
10+
11+
Row = 4
12+
10
13+
I H
14+
7 6 5
15+
D C B A
16+
17+
USE THIS FOR LOOP STRICTLY for the outer loop
18+
Int row;
19+
Take row from user
20+
for(int i =1;i<=row;i++){
21+
22+
}
23+
*/
24+
25+
26+
package For.Assignment.Assignment07;
27+
import java.io.BufferedReader;
28+
import java.io.InputStreamReader;
29+
30+
public class program6 {
31+
public static void main(String[] args)throws Exception {
32+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
33+
34+
System.out.println("Enter the Number of rows : ");
35+
int row = Integer.parseInt(br.readLine());
36+
37+
int num = ((row * row) + row) / 2;
38+
char ch = (char)(64 + ((row * row) + row) / 2);
39+
40+
for(int i = 1; i <= row; i++){
41+
42+
for(int j = 1; j <= i; j++){
43+
44+
if( row % 2 == 1){
45+
if(i % 2 == 0){
46+
47+
System.out.print(num + " ");
48+
}else{
49+
50+
System.out.print(ch + " ");
51+
}
52+
ch--;
53+
num--;
54+
}
55+
56+
else{
57+
58+
if(i % 2 != 0){
59+
60+
System.out.print(num + " ");
61+
}else{
62+
63+
System.out.print(ch + " ");
64+
}
65+
ch--;
66+
num--;
67+
}
68+
69+
}
70+
System.out.println();
71+
}
72+
}
73+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
/*
3+
Program 8 : write a program to print the following pattern
4+
Row =8
5+
$
6+
@ @
7+
& & &
8+
# # # #
9+
$ $ $ $ $
10+
@ @ @ @ @ @
11+
& & & & & & &
12+
# # # # # # # #
13+
USE THIS FOR LOOP STRICTLY for the outer loop
14+
Int row;
15+
16+
Take row from user
17+
for(int i =1;i<=row;i++){
18+
19+
}
20+
*/
21+
22+
package For.Assignment.Assignment07;
23+
import java.io.BufferedReader;
24+
import java.io.InputStreamReader;
25+
26+
public class program7 {
27+
public static void main(String[] args)throws Exception {
28+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
29+
30+
System.out.println("Enter the Number of rows : ");
31+
int row = Integer.parseInt(br.readLine());
32+
33+
for(int i=1;i<=row;i++)
34+
{
35+
for(int j=1;j<=i;j++)
36+
{
37+
if(i%4==0)
38+
{
39+
System.out.print("#"+" ");
40+
}
41+
42+
else if(i%2==0)
43+
{
44+
System.out.print("@ ");
45+
}
46+
47+
else if(i%3==0)
48+
{
49+
System.out.print("& ");
50+
}
51+
52+
else
53+
{
54+
System.out.print("$ ");
55+
}
56+
}
57+
System.out.println();
58+
}
59+
}
60+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
/*
3+
Program 9 : Write a program to take a number as input and print the Addition of Factorials of each
4+
digit from that number.
5+
Input: 1234
6+
Output: Addition of factorials of each digit from 1234 = 33
7+
*/
8+
9+
package For.Assignment.Assignment07;
10+
import java.io.BufferedReader;
11+
import java.io.InputStreamReader;
12+
13+
public class program9 {
14+
public static void main(String[] args)throws Exception {
15+
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
18+
System.out.println("Enter the Number : ");
19+
int num = Integer.parseInt(br.readLine());
20+
21+
int temp = num;
22+
int sum =0;
23+
while(num!=0)
24+
{
25+
int rem = num % 10;
26+
int fact =1;
27+
for(int i=1;i<=rem;i++)
28+
{
29+
fact = fact * i;
30+
}
31+
sum +=fact;
32+
num /=10;
33+
}
34+
35+
System.out.println("Addition of factorials of each digit from "+temp+" is "+sum);
36+
37+
}
38+
39+
40+
}

0 commit comments

Comments
 (0)