COMPUTER PROJECT
For loop
Import java.io.*;
Import java.util.*;
Import java.lang.*;
Public class 1
Public static void main (String args [])
int i, j, k;
for (i=5; i>=0; i--)
for (j=1; j<=I; j++)
System.out.print (“1”);
for (k=1; k<= (6-i); k++)
System.out.print (k);
System.out.println ();
Output
12
123
1234
12345
1234
123
12
1
Import java.io.*;
Import java.util.*;
Import java.lang.*:
Public class 2
Public static void main (String args [])
int w, x, y, z;
for (w=1; w<=5; w++)
for (x=1; x<=w; x++)
System.out.print(x);
System.out.println ();
for (y=4; y>=1; y--)
for (z=1; z<=y; z++)
System.out.print(z);
System.out.println ();
Output
1 12345 1
12 1234
123 123
1234 12
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 3
Public static void main (String args [])
int w, x, y, z;
for (w=5; w>=2; w--)
for (x=1;x<=w;x++)
System.out.print(x);
System.out.print( );
for (y=1;y<=5;y++)
for (z=1;z<=y;z++)
System.out.print(z);
System.out.println ();
Output
12345 123
1234 1234
123 12345
12
12
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 4
Public static void main (String args [])
int w, x ;
for (w=1; w<=5; w++)
for (x=1;x<=w;x++)
System.out.print(x+ “ ” );
for (y=w-1;y>=1;y--)
System.out.print(y+ “ ”);
System.out.println ();
output
121
12321
1234321
123454321
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 5
Public static void main (String args [])
int w, x;
for (w=1; w<=6; w++)
If (x% 2==0)
System.out.print(“0”);
else
System.out.print(“1” );
System.out.println ();
Output
10
101
1010
10101
101010
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 6
Public static void main (String args [])
{
int l,m,n;
for (l=1; l<=5; l++)
{
for (m=1; m<=l-1; m++)
{
System.out.print(“ “);
}
for (n=l;n<=5;n++)
{
System.out.print(n);
}
System.out.println ();
}
for (l=4;l<=1;l--)
{
for (m=1; m<=l-1; m++)
{
System.out.print(“ ”);
}
for (n=l;n<=5;n++)
{
System.out.print(n);
}
System.out.println ();
}
}
Output
12345 12345
2345
345
45
345
2345
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 7
Public static void main (String args [])
int l,m;
for (l=1; l<=7; l++)
for (m=1; m<=7; m++)
If (l+m% 2==0)
System.out.print(“1”);
else
System.out.print(“0” );
System.out.println ();
Output
1010101
0101010
1010101
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 8
Public static void main (String args [])
int w, x, y, z;
for (w=1; w<=6; w++)
for (x=w;x<=6;x++)
If (b% 2==0)
System.out.print(“0”);
else
System.out.print(“1” );
System.out.println ();
Output
0000000
0100000
0020000
0003000
0000400
0000050
0000006
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 9
Public static void main (String args [])
{
int l,m,n;
for (l=1; l<=5; l++)
{
for (m=1; m<=l-1; m++)
{
System.out.print(“ “);
}
for (n=l;n<=5;n++)
{
System.out.print(“ “+n);
}
System.out.println ();
}
for (l=4;l<=1;l--)
{
for (m=1; m<=l-1; m++)
{
System.out.print(“ ”);
}
for (n=l;n<=5;n++)
{
System.out.print(“ “+n);
}
System.out.println ();
}
}
Output
12345 2345
2345 12345
345
45
45
345
Import.io.*;
Import.util.*;
Import.lang.*;
Public class 10
Public static void main (String args [])
int l,m,n,no;
Scannerkb=new Scanner (System.in);
System.out.print(“enter a no”);
n=kb.nextInt();
for(l=1;l<=n;l++)
No=l;
for(m=1;m<=l;m++)
System.out.print(no+” “);
no=no+(n-m);
System.out.println();
Output
26
3 7 10
4 8 11 13
5 9 12 14 15