In: Computer Science
write a java code program using loops to compute the sum of the 30 terms of the series below.
Find sum of all integers between 100 and 200 which are divisible by 9 or 13 Write a program to find the sum of the first 8 terms of the series 1 + 11 + 111 + 1111 + . . .
Output:
Term Ratio Sum
1)
Java code:
public class Main
{
public static void main(String[] args) {
//initializing sum as 0
int sum=0;
//looping from 100 to
200
for(int
i=100;i<=200;i++)
//checking if number is
divisible by 9 or 13
if(i%9==0 || i%13==0)
//adding it to sum
sum+=i;
//printing Sum
System.out.println("Sum="+sum);
}
}
Screenshot:
Output:
2)
Java code:
public class Main
{
public static void main(String[] args) {
//initializing sum as 0 and
num as 0
int sum=0,num=0;
//looping for 8 times
for(int
i=0;i<8;i++){
//finding
current term
num=num*10+1;
//adding it
to sum
sum=sum+num;
}
//printing Sum
System.out.println("Sum="+sum);
}
}
Screenshot:
Output: