0 1 Floyd’s triangle coderinme

0 1 Floyd’s triangle coderinme

We already know that a 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

So let us now modify the program to produce the following form of Floyd’s triangle.
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1

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%2));
k++;
}
System.out.println(" \n ");
}
}
}

For more programs on Java, visit our Java Archives

0 1 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.