Question

In: Computer Science

Write a Java program to find the sum of all integers between 200 to 250 which...

Write a Java program to find the sum of all integers between 200 to 250 which are divisible by 7.

Sample Output:
Numbers between 200 and 250, divisible by 7:
203 210 217 224 231 238 245
The sum is: 1568

Solutions

Expert Solution

Below is the code in java with className as "Main"(Main.java). If you wish to save the file name as suppose(Xyz.java), change the Class name from 'Main'(in first line of program)  to whatever you wish (Xyz). attached the code image as well and the output result's image)

public class Main
{
        public static void main(String[] args) 
        {
            int sum=0;
                System.out.println("Sample Output:\n");
                System.out.println("Numbers between 200 and 250, divisible by 7: ");
        
        for(int i=200;i<250;i++)
        {
            if(i%7==0)
            {
                System.out.print(i+"   ");
                sum =sum+i;
            }
        }
        
        System.out.println("\nThe sum is: "+sum);
    }
}

Code image :(change the highlighted part(className) if you wish to save the file with some other name. Suppose if you want to save this java file as (Water.java), change the highlighted part(marked in below image)(very first line of code) from 'Main' to 'Water'.

Output result :


Related Solutions

Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
Write a program in java which store 10 numbers and find the sum of odd and...
Write a program in java which store 10 numbers and find the sum of odd and even numbers. Create a program that uses a two dimensional array that can store integer values inside. (Just create an array with your own defined rows and columns). Make a method called Square, which gets each of the value inside the array and squares it. Make another method called ShowNumbers which shows the squared numbers. Write a program in java which has an array...
Write a program in java which store 10 numbers and find the sum of odd and...
Write a program in java which store 10 numbers and find the sum of odd and even numbers. Create a program that uses a two dimensional array that can store integer values inside. (Just create an array with your own defined rows and columns). Make a method called Square, which gets each of the value inside the array and squares it. Make another method called ShowNumbers which shows the squared numbers.
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers...
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers between a given range (limit your range from 0 to 50). For example, if the user want to add the integers between (and including) 1 and 10, then the program should add: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 Algorithm: Program title/description Ask the user to input a start value in the...
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
2. Answer the following question (a) Write a Java program to find the number of integers...
2. Answer the following question (a) Write a Java program to find the number of integers within the range of two specified numbers and that are divisible by another number. For example, x = 5, y=20 and p =3, find the number of integers within the range [x, y] and that are divisible by p. (b) Write explicitly on the following OOP concepts: i. Encapsulation ii. Inheritance iii. Polymorphism (c) Develop a Java application that computes the two roots of...
Write a program that will sum the integers between a given range (limit your range from...
Write a program that will sum the integers between a given range (limit your range from 0 to 50). For example, if the user want to add the integers between (and including) 1 and 10, then the program should add: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 Algorithm: Program title/description Ask the user to input a start value in the range 0 to 50. Remember to create the...
Write a program in Java which will search a space delimited string of integers for the...
Write a program in Java which will search a space delimited string of integers for the two values which add up to a provided amount. The program must output th following text to the command prompt/console: Indexes: { Index of first number} { Index of second number} Example One: NumSerach( 100, " 5 75 25"); output: Indexes: 1 2
JAVA Write a program that reads the integers between -100 and 100 and counts the occurrences...
JAVA Write a program that reads the integers between -100 and 100 and counts the occurrences of each with ascending order. input: line1:number of figures line2:number Sample Input 5 -3 100 -1 -2 -1 Sample Output -3 1 -2 1 -1 2 100 1
Write a program that will calculate the sum of the first n odd integers, and the...
Write a program that will calculate the sum of the first n odd integers, and the sum of the first n even integers. Use a Do while loop Use a for loop Here is a sample of how the program should run: How many odd integers would you like to add? 5 Count Odd Integer Sum 1 1 1 2 3 4 3 5 9 4 7 16 5 9 25 The sum of the first 5 odd integers is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT