Number Pattern 1 using Loop in Java

0
39

 

This tutorial entitles “Number Pattern 1 using Loop in Java” will teach you on how you can display a number pattern forming a triangle using for loop. Please follow all the steps to complete this tutorial.

Looping is a common feature use in any programming language especially in Java Program. This is a repetition statement with condition. If the condition is meet, the repetition or the looping stop.  There are three types of loop, the while loop, do while loop, and for loop.

Number Pattern 1 using Loop in Java Steps

  1. Create a new class and name it what you want to name.
How Print Hello World Text in Java, Sum Two Integers Values using Java
How Print Hello World Text in Java

2. Create a main method inside your class.

  1. public static void main(String args[]){
  2.  
  3. }

3. Insert the code below inside your main method for looping.

  1. for (int i = 1; i <=5;i++){
  2. for (int j = 1;j <= i;j++){
  3. System.out.print(j);
  4. }
  5. System.out.println();
  6. }

Remember: 1 start the looping and 5 end the looping.

4. Run your program and the output should look like the image below.

5. Complete Source Code

  1. public class PatternNumber1 {
  2. public static void main(String args[]){
  3. for (int i = 1; i <=5;i++){
  4. for (int j = 1;j <= i;j++){
  5. System.out.print(j);
  6. }
  7. System.out.println();
  8. }
  9. }
  10. }

Suggested Topic you may Like:

How to Check Highest Number in Java

Loop control In Java

Sum of Two Integers using Java

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here