Assignment: Module 03- Part 02
Write a class FloydExample3 to display the output as below using control structures enter the value of Floyd triangle 4
Output:
0
01
010
0101
Here is the Java code to display the output as described:
import java.util.Scanner;
public class FloydExample3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of Floyd triangle: ");
int n = sc.nextInt();
sc.close();
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print("0");
}
System.out.println();
}
}
}
And here is the output for n = 4:
Enter the value of Floyd triangle: 4
0
01
010
0101