Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that processes input lines until the user enters a terminating newline character. Each of the other lines is expected to be

Write a Java program that processes input lines until the user enters a terminating newline character. Each of the other lines is expected to be a string consisting of digits and space characters. Each digit sequence is a token detected by the scanner and can be converted into a number. The program scans the string and prints the tokens (digit sequences in the string). It also prints the sum and product of the numbers denoted by the tokens on the line. It should print each token and the sum and product on a different line. 

It does this for each input line other than the terminating line. 

Thus, the tokens produced by your scanner denote numbers. Later your program will recognize other kinds of tokens such as words and quote characters. 

You can assume that there is: 

  1. exactly one space character after each token
  2. at least one token in each input line. 
  3. line consists of only spaces and digits. The following example illustrates the nature of the expected program behavior for two input lines and a terminating line, in italics: 
  4. The program ends when the end-user types in "Goodbye".

EXAMPLE

String? 

2 3 100 

Tokens: 

100 

Sum: 105 

Product: 600 

 

String? 

4 6 20 

Tokens: 

20 

Sum: 30 

Product: 480 

String? 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Here is a sample Java program that implements the functionality described java import javautilScanne... 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

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

Students also viewed these Programming questions

Question

plz help Journal entry worksheet

Answered: 1 week ago

Question

Show that [see (8. 39)]. av. var () 1 TIZ t-1 Exa

Answered: 1 week ago