Floyd’s triangle parogram in java

Java code to print the Floyd’s triangle




import java.io.*;

class Test {
     public static void main(String[] args) throws IOException {
         
          int i,j,r,k=1;
          System.out.println("Enter the range:");
          BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
          r=Integer.parseInt(br.readLine());
          System.out.println("FLOYD'S TRIANGLE");

          for(i=1;i<=r;i++){
              for(j=1;j<=i;j++,k++)
                   System.out.print("  "+k);
              System.out.print("\n");
          }
         
     }

2 comments:

raagu sd said...

Wrong logic. Violates n*(n+1)/2 equality.

Modern Pathshala said...

Nice post. Check list of Java programming interview questions at http://modernpathshala.com/Learn/Java/Assessment