Program 1:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
*
**
***
****
*****
Program 2:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println("");
}
for(i=5;i>=1;i--){
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
*
**
***
****
*****
*****
****
***
**
*
Program 3:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=5;i>=1;i--){
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println("");
}
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
*****
****
***
**
*
*
**
***
****
*****
Program 4:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print("*");
for(j=1;j<i;j++)
System.out.print("*");
System.out.print("\n");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
*
***
*****
*******
*********
Program 5:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print(" "+i);
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Program 6:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print(" "+i);
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Program 7:-
class Main{
public static void main(String args[]){
int i,j;
for(i=1;i<=10;i++){
for(j=1;j<=10;j++)
System.out.print(" "+i*j);
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java Main
1
2 3 4
5 6 7 8
9 10
2 4
6 8 10 12
14 16 18 20
3 6
9 12 15 18 21
24 27 30
4 8 12
16 20 24 28 32
36 40
5 10 15
20 25 30 35 40
45 50
6 12 18
24 30 36 42 48
54 60
7 14 21
28 35 42 49 56
63 70
8 16 24
32 40 48 56 64
72 80
9 18 27
36 45 54 63 72
81 90
10 20 30 40
50 60 70 80 90 100
Program 8:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print(" "+j);
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program 9:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(j=1;j<=i;j++)
System.out.print(" ");
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program 10:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print("
"+(i+j)%2);
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
Program 11:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println(" ");
}
for(i=1;i<=5;i++){
for(j=5;j>=i;j--)
System.out.print("*");
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac 1.java
C:\Users\Saty\Desktop\java>java
Main
*
**
***
****
*****
*****
****
***
**
*
Program 12:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=i;j<=5;j++)
System.out.print(" "+j);
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
Program 13:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print("*");
for(j=1;j<i;j++)
System.out.print("*");
System.out.println("");
}
for(i=1;i<=5;i++){
for(j=1;j<i;j++)
System.out.print(" ");
for(j=10-i;j>=i;j--)
System.out.print("*");
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
*
***
*****
*******
*********
*********
*******
*****
***
*
Program 14:-
class Main{
public static void main(String
args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print("*");
for(j=1;j<i;j++)
System.out.print("*");
System.out.println("");
}
for(i=1;i<=5;i++){
for(j=1;j<i;j++)
System.out.print(" ");
for(j=5;j>=i;j--)
System.out.print("*");
for(j=5;j>i;j--)
System.out.print("*");
System.out.println("");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
*
***
*****
*******
*********
*********
*******
*****
***
*
Program 15:-
class Main{
public static void main(String args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(j=i-1;j>=1;j--)
System.out.print(" "+j);
System.out.println(" ");
}
for(i=4;i>=1;i--){
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(j=i-1;j>=1;j--)
System.out.print(" "+j);
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Program 16:-
class Main{
public static void main(String args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print(" ");
for(j=10-i;j>=i;j--)
System.out.print("*");
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
*********
*******
*****
***
*
Program 17:-
class Main{
public static void main(String args[]){
int i,j,k=1;
for(i=0;i<=5;i++){
for(j=1;j<=5-i;j++)
System.out.print(" ");
for(j=0;j<=i;j++){
if(j==0||i==0)
k=1;
else
k=(k*(i-j+1)/j);
System.out.print(" "+k);
}
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Program 18:-
class Main{
public static void main(String args[]){
int i,j,k=1;
for(i=1;i<=4;i++){
for(j=1;j<=i;j++,k++)
System.out.print(" "+k);
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
1
2 3
4 5 6
7 8 9 10
It,s nice thanks for your codes
ReplyDeletethank U .........
ReplyDeletefor giving me a great examples
Thank You so Much Sir...Its really awesome!!!
ReplyDeletenot even my coachings provided such a great programs
This was great, loved it, thank you.
ReplyDeleteWow good teaching. Why can't more people think in a logical manner like you?
ReplyDeletehave to recommend it to beginners
ReplyDeleteExcellent! You are an excellent teacher. Loved this
ReplyDeleteGreat instructional codes. Thanks a ton
ReplyDeleteThis was fabulous - thank you so much for creating this training!
ReplyDeleteThis is the most efficient way I could have learned Java.Thank you very much.
ReplyDeleteYour teaching is highly organized and structured. Feeling lucky to find you. God bless you.
ReplyDeleteit is the only code that i have found which helps and is easy to follow for beginners
ReplyDelete