Computer Science, asked by Sayani07, 10 months ago

Wap in java to get an output




1
12
123
1234​

Answers

Answered by atrs7391
1

Easiest program:

package com.company;  

public class Main {

  public static void main(String[] args) {

      int s = 0;

      for (int i = 1; i <= 4 ; i++) {

          s = s*10+i;

          System.out.println(s);

      }

  }

}

Output:

1

12

123

1234

Answered by purveshKolhe
3

\huge{\purple{\underline{\underline{\mathfrak{\red{\bigstar answer:: \bigstar}}}}}}

public class Main {

  public static void main(String [] args) {

     for (int i = 1; i <= 4; i++) {

        for (int n = 1; n <= i; n++) {

           System.out.print(n);

        }

        System.out.print("\n");

     }

  }

}

\gray{\rule{300pt}{0.3em}}

\huge{\purple{\underline{\underline{\mathfrak{\red{\bigstar Logic:: \bigstar}}}}}}

  • The class name is declared as "i"
  • Then comes the main method where all the legal code goes in.
  • We executed a loop for the variable "i" from 1 to 4.
  • There is one more same loop but with variable "n" nested inside the 'i loop'.
  • Then we print the variable "n" inside the loop.
  • Outside this loop, we print the newline character to print the series accurately.
  • And we finished it...

\gray{\rule{300pt}{0.3em}}

Hope it helps..♪

Similar questions