Computer Science, asked by moon8577, 4 months ago

please solve this using while loop only ​

Attachments:

Answers

Answered by kamalrajatjoshi94
0

Answer:

Program using while loop:-

import java.util.*;

public class Series

{

public static void main(String args[ ])

{

Scanner in=new Scanner(System.in);

int n,a=1,term=1;

System.out.println("Enter n");

n=in.nextInt();

System.out.println("The series");

while(a<=n)

{

System.out.print(term+ " ");

term=term*10+1;

a++;

}

}

}

Using for loop:-

for(a=1;a<=n;a++)

{

System.out.print(term+ " ");

term=term*10+1;

}

Answered by anindyaadhikari13
1

Answer:

This is the required program for the question.

import java.util.*;

public class Java {

 public static void main(String[] args) {

     int n, i=1, a=1;

     Scanner sc=new Scanner(System.in);

     System.out.print("Enter limit - ");

     n=sc.nextInt();

     while (i<=n)  {

        System.out.print(a+" ");

        a=a*10+1;

        ++i;

     }

     sc.close();

 }

}

Algorithm:

  1. START.
  2. Accept the limit.
  3. Initialise a=1
  4. Iterate a loop n times.
  5. Display the value of a.
  6. Multiply a with 10 and add 1 to it. Store the result in a.
  7. STOP.

See the attachment for output .

Attachments:
Similar questions