how to ptint the series in java
1, 11, 111, 1111 ....n
Answers
Answer:
import java.util.Scanner;
public class Series
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of terms: ");
int n = sc.nextInt();
int s = 0, c; // s for terms of series, c for n terms
for (c = 1; c <= n; c++) // To generate n terms
{
s = s * 10 + 1;
System.out.print(s + " ");
} //for ends
}
}
Output:
Enter the number of terms: 7
1, 11, 111, 1111, 11111, 111111, 1111111......
BUILD SUCCESSFUL (total time: 3 seconds
hope this help you.
mark as best as your wish.
Question:-
Write a program in Java to print the series.
1 11 111 1111...N
Program:-
import java.util.*;
class Series
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of terms for the series: ");
int n=sc.nextInt();
int a=1;
for(int i=1;i<=n;i++,a=a*10+1)
System.out.print(a+" ");
}
}