/*
1. Example:
1
01
101
0101
*/
public class FloydsTriangle{
/**
* @param args
*/
public static void main(String[] args) {
for(int i=1;i<5;i++){
for(int j=1;j<=i;j++){
if( i == j){
System.out.print("1");
} else if( (i+j)%2 == 0){
System.out.print("1");
}else{
System.out.print("0");
}
}
System.out.println(" ");
}
}
}
/*
Output:
1
01
101
0101
01
101
0101
*/
---------------------------------------------------------------------------------------------------
2.Example :
1
22
333
4444
55555
55555
4444
333
22
1
---------------------------------------------------------------------------------------------------------
3.Example
---------------------------------------------------------------------------------------------------
2.Example :
1
22
333
4444
55555
55555
4444
333
22
1
public class FloydsTriangle2{
/**
* @param args
*/
public static void main(String[] args) {
/**
* @param args
*/
public static void main(String[] args) {
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
System.out.print(i);
}
System.out.println("");
}
for(int i=5;i>0;i--){
for(int j=1;j<=i;j++){
System.out.print(i);
}
System.out.println("");
}
}
}
3.Example
1
22
333
4444
55555
public class FloydsTriangle2{
/**
* @param args
*/
public static void main(String[] args) {
/**
* @param args
*/
public static void main(String[] args) {
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
System.out.print(i);
}
System.out.println(" ");
}
}
}
--------------------------------------------------------------------------------------
4. Example
1
12
123
1234
12345
--------------------------------------------------------------------------------------
4. Example
1
12
123
1234
12345
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
System.out.print(j);
}
System.out.println(" ");
}
----------------------------------------------------------------------------------------------
No comments:
Post a Comment