Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1
java program to print floyd's triangle
Java Examples

java program to print floyd’s triangle

Table of Contents

FloydTriangle.java

import java.util.Scanner;
/**
 * @author Candid Java
 */

class FloydTriangle {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  System.out.println("Enter the number of rows: ");
  int r = sc.nextInt(), n = 0;
  sc.close();
  for (int i = 0; i < r; i++) {
   for (int j = 0; j <= i; j++) {
    System.out.print(++n + " ");
   }
   System.out.println();
  }
 }
}

Output

Enter the number of rows: 5
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15