Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that, given an integer, sums all the numbers from 1 through that integer (both inclusive). Do not include in your sum any

Write a program that, given an integer, sums all the numbers from 1 through that integer (both inclusive). Do not include in your sum any of the intermediate numbers (1 and n inclusive) that are divisible by 5 or 7.

Input:

Your program should read lines from standard input. Each line contains a positive integer.

Output:

For each line of input, print to standard output the sum of the numbers from 1 through n, disregarding those divisible by 5 and 7. Print out each result on a new line.

The code is then

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets;

public class Main { /** * Iterate through each line of input. */ public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

What is the major weakness of the unadjusted rate of return method?

Answered: 1 week ago

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago

Question

=+ b. What is the per-worker production function, y = f(k)?

Answered: 1 week ago