please solve this using while loop only
Attachments:
Answers
Answered by
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
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:
- START.
- Accept the limit.
- Initialise a=1
- Iterate a loop n times.
- Display the value of a.
- Multiply a with 10 and add 1 to it. Store the result in a.
- STOP.
See the attachment for output ☑.
Attachments:
Similar questions