Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java. Scanner. Sum. Using Scanner 1) Import the java.util.Scanner package at the top of your Java file. 2) Create an instance of Scanner and pass

Java. Scanner. Sum.

Using Scanner

1) Import the java.util.Scanner package at the top of your Java file.

2) Create an instance of Scanner and pass the parameter System.in.

3) Invoke the method scanner.nextInt() to read an integer, scanner.nextDouble() to read a double, scanner.next() to read a String, scanner.nextLine() to read an entire line as a String, and so on. See the following example for usage:

import java.util.Scanner; public class ScannerExample { public void readUserInput(){ Scanner scanner = new Scanner(System.in); int nextInt = scanner.nextInt(); System.out.println(nextInt); } }

Write a JAVA program that sums a group of integer inputs entered by a user and prints the result. Assume that the first integer entered specifies the number of values remaining to be entered. An example input sequence might be: 5 100 200 300 400 500

1) Open the IDE of your choice.

2) Create a new class named Summation.

3) Modify your code using the following sample:

 import java.util.Scanner; public class Summation { public static void main(String[] args) {
 sumIntegers(); } /* This method takes input from the user and produces the summation */ public static void sumIntegers(){ //write your code here } }

4) Create your main method and invoke sumIntegers method from main.

5) Implement the sumIntegers method.

6) Test the sumIntegers method and verify the output. See the example output:

How many integers will be summed? 5 Enter an integer: 100 Enter an integer: 200 Enter an integer: 300 Enter an integer: 400 Enter an integer: 500 The Summation is: 1500 

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

Step: 3

blur-text-image

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago