Series 8
1+11+111+1111+11111+..........upto n terms.
import java.util.*;
class Series10
{
public static void main(String args[])
throws InputMismatchException{
Scanner scan=new Scanner(System.in);
System.out.println("Enter the limit: ");
int n = scan.nextInt();
int i, a=0, s=0;
for(i=1;i <= n; i++){
a = a*10 + 1; //generates 1, 11, 111, ...
s = s + a;
}
System.out.println("Sum = "+s);
}//end of main
}//end of class
Have something to say? Log in to comment on this post.
0 comments