Answer to Question #278048 in Java | JSP | JSF for Akemi

Question #278048

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



Or


Input


4




Output


1


23


4




Or input


12



Output


1


23


456


78910


1112

1
Expert's answer
2021-12-11T01:57:36-0500
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int number = scanner.nextInt();
    int x = 1, n = 1;
    while (x <= number) {
      for (int i = 0; i < n; i = i + 1)
        if (x <= number)
          System.out.print(x++);
      System.out.println();
      n = n + 1;
    }
  }
}

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