Answer to Question #269183 in Java | JSP | JSF for harryy

Question #269183

You probably have encountered Triangle pattern problems before when you started learning programming. Let’s see how well you do with numbers this time. Try to look at the examples closely and think of an algorithm that replicates the outputs. Go for it!


Input

A single line containing an integer n.

9

Output

The output generated based on the inputted integer n.

1
23
456
789
1
Expert's answer
2021-11-21T04:57:58-0500


package triangle;


import java.util.Scanner;




public class Triangle {


  
    public static void main(String[] args) {
        int k =1;
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i=0; i<n; i++){
            
            for(int j=0; j<=i; j++){
                System.out.print(k);
                k++;
            }
            System.out.println( );
        }
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS