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
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...
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 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 Java program with comments that randomly generates an array of 500,000 integers between 0...
Write a Java program with comments that randomly generates an array of 500,000 integers between 0 and 499,999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); perform the task; long endTime =...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
Java Write a program that displays all the numbers from 100 to 200 that are divisible...
Java Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both Make sure all instructions and outputs for the user are explicit
• Write a C++ program to find the largest umber, smallest number and sum of all...
• Write a C++ program to find the largest umber, smallest number and sum of all the element of a given array of 20 integers • Note − Declare array to 20 numbers − Input values for 20 array elements − Find largest number − Find smallest number − Find sum of all numbers • Display the results
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT