Logic Number Pattern in Java 2024

Best Logic Pattern in Java with solution.

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

class HelloWorld {
    public static void main(String args[]){
        int row , col , k;
        for( row =1 ; row <= 5 ; row ++) { 
            k = row ;
            for( col =1 ; col <= row ; col ++)  {
                System.out.print(k+" ");
                k = k +( 5 - col );
            }
            System.out.print("\n");
        }
    }
}

The First for loop is regular for 5 rows for this Logic on the second for loop we can write some logic.
Second for loop:-

k = row ;
for( col =1 ; col <= row ; col ++) {
System.out.print(k+” “);
k = k +( 5 – col );
}


In this loop for row = 1: It runs only for one time.
In this loop for row = 2: When row = 2 that time value of K variable id 2 first it print K that is 2 then
k = k +( 5 – col );

k=2, col =1;
this logic changes the value of k that is : k = 2+(5-1) so value of k is 6.


प्रत्येक row :

k = row ;
for( col =1 ; col <= row ; col ++) {
System.out.print(k+” “);
k = k +( 5 – col );
}

हे लूप निर्वाह करताना, प्रत्येक पंक्तीसाठी:

  • पंक्ती = 1: त्यात केवळ एकदा चालते.
  • पंक्ती = 2: पंक्ती = 2 असून तेव्हा k चे मूल्य 2 आहे. पहिल्यांदा kचे मूल्य प्रिंट होते ते म्हणजे 2 नंतर k = k +( 5 – col );


For More Patterns in Java code => Click Here.

If you have any questions on any pattern comment below.

Leave a Comment