DEV Community

yaswanth krishna
yaswanth krishna

Posted on

while using 1 to 25 looping statements

1 to 25 print them while loop using statement?

package hlo;

public class upperlinit {

    public static void main(String[] args) {
//      int no=1;

//      while(no<=5) {
//          System.out.println(no);
//          no=no+1;
//          
//      }
//      while(no<=10) {
//          System.out.println(no);
//          no=no+1;
//          
//      }
//      while(no<=15) {
//          System.out.println(no);
//          no=no+1;
//          
//      }
//      while(no<=20) {
//          System.out.println(no);
//          no=no+1;
//          
//      }
//      while(no<=25) {
//          System.out.println(no+"");
//          no=no+1;
//          
//      }



Enter fullscreen mode Exit fullscreen mode

it's using hard task you take easy method calfare next code i will explain.

package hlo;

public class upperlimit {

    public static void main(String[] args) {
int no=1;
        int upper_limit=25;
        while(upper_limit<=25) {
            while(no<=25) {
                System.out.println(no);
                no=no+1;
            }
            System.out.println();
            upper_limit=upper_limit+5;
        }

    }

}

Enter fullscreen mode Exit fullscreen mode

`output:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

`

Top comments (0)