Computer Science, asked by jayesh7thfebtl, 10 months ago

1,12,123,1234....
write a program in java to print above series first ten terms

Answers

Answered by ridhimakh1219
24

1,12,123,1234....

write a program in java to print above series first ten terms

Explanation:

Java program to print series 1 12 123 1234 12345..

import java.util.Scanner;

public class Main

{

public static void main(String args[])

{

 Scanner sc = new Scanner(System.in);

 System.out.print("Enter the number of terms: ");

 int num = sc.nextInt();

 int s = 0, i;

 for (i = 1; i <= num; i++) {

  s = s * 10 + i;

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

 }

}

}

Output of a program

Enter the number of terms: 10

1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567900  

Answered by aritra4467
6

Explanation:

1,12,123,1234....

write a program in java to print above series first ten terms

Explanation:

Java program to print series 1 12 123 1234 12345..

import java.util.Scanner;

public class Main

{

public static void main(String args[])

{

 Scanner sc = new Scanner(System.in);

 System.out.print("Enter the number of terms: ");

 int num = sc.nextInt();

 int s = 0, i;

 for (i = 1; i <= num; i++) {

  s = s * 10 + i;

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

 }

}

}

Output of a program

Enter the number of terms: 10

1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567900

Similar questions