Computer Applications
Write a program to find the number of and sum of all integers greater than 500 and less than 1000 that are divisible by 17
Java
Java Conditional Stmts
16 Likes
Answer
public class KboatDivisibleBy17
{
public static void main(String args[]) {
int sum = 0, count = 0;
for (int i = 501; i < 1000; i++) {
if (i % 17 == 0) {
count++;
sum += i;
}
}
System.out.println("Sum = " + sum);
System.out.println("Count = " + count);
}
}
Output
Answered By
5 Likes
Related Questions
Create a program to find out if the number entered by the user is a two, three or four digits number.
Sample input: 1023
Sample output: 1023 is a 4 digit number.Find the errors in the following code and rewrite the correct version:
char m="A"; Switch ("A"); { Case 'a'; System.out.println("A"); break; Case 'b'; System.out.println("B"); break; Default: System.out.println("Not a valid option"); }
Write a program in Java that reads a word and checks whether it begins with a vowel or not.
What will be the output of the following code?
int x=2,y=5,a=0; a=x; x=y; y=a; System.out.println("x=" + x + " y=" + y);