Computer Science, asked by amarjeetmurmu, 11 months ago

Write the programs in Java to display the first ten terms of the following series: 1, 12, 123, 1234, ...............​

Answers

Answered by gurudattchoudhary
9

Answer:

Home � Core Java , Interview Question , Programs , Series , Written Test � Print Series 1, 12, 123, 1234, …………n in Java.

Print Series 1, 12, 123, 1234, …………n in Java.

Unknown | 11:36:00 AM | 2 comments

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 counter to generate n terms

for (c = 1; c <= n; c++) {

s = s * 10 + c;

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

}

}

}

Output:

Enter the number of terms: 6

1, 12, 123, 1234, 12345, 123456.......

BUILD SUCCESSFUL (total time: 3 seconds)

Similar questions