Computer Science, asked by keertanachiguru2537, 9 months ago

Print the output of the series Write a java program to print this series 1+12+123....n

Answers

Answered by Anonymous
2

Answer:

Hope you like the code !!

(P.S. - Mark as Brainliest if you like it !!)

Explanation:

import java.util.Scanner;

public class Number_loop

{

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+" ");

 }

}

}

Answered by tamaghnadey1916
0

Answer:

Your code in JAVA:-

import java.util.*;

class series

{

public static void main ()

{

Scanner sc=new Scanner (System.in);

int i,n,k=0,s=0;

System.out.println ("Enter no. of terms for your series");

n=sc.nextInt ();

System.out.print ("Required Series Sum:");

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

{

k=k*10+i; //concats the value of i on its right

s+=k; //makes the sum a told in the que

}

System.out.print (s);

}}

// end of the program

Explanation:

The value of i iterates from 1 to the input term value n

k is required to concat the value of i in its right a i increases by 1

s is required to find the sum of all concatenated values.

I hope this helps you

DON' T FORGET TO MARK ME THE BRAINLIEST

BYE

Similar questions