Floyd’s triangle coderinme

Floyd’s triangle coderinme

Floyd’s triangle is a right-angled triangular array of natural numbers, used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
We start by asking for the numbers of rows we want to print of the Floyd´s triangle. After we have entered a number we start the first for loop. The second for loop that is where we print the numbers, after the print we do number = number + 1. It prints numbers until we are equal to a of the first for loop. We then go to a newline.

Program:

import java.io.*;
public class Q12
{
public static void main(String[] args) 
{
int k=1;
for(int i=1;i<=5;i++) 
{
for(int j=1;j<=i;j++) 
{
System.out.print(" " +k);
k++;
}
System.out.println(" \n ");
}
}
}

For more programs on Java, visit our Java Archives

Floyd’s triangle coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.