Results 1 to 2 of 2
- 10-20-2008, 07:42 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 25
- Rep Power
- 0
How to ask for several integers from the program user?
I need to write a program in which you ask the user to input a bunch of integers (no set amount, as many as they want) in one line and then the line adds up all the integers that are positive and sets the value of that line equal to the sum.
So, I was wondering if I need to use a command that specifically sets a variable value to a list, or stack? because we haven't really learned about arrays yet?.
pasted the assignment:
(10 marks) A set of data is to be read and manipulated. You can read the data from standard input (i.e., from a user typing in a console window, or from a file using input redirection) or from JOptionPane dialog boxes. The number of lines is unknown. Each line of data contains
a line number, like 1., 2., 3., etc.
an integer n,
followed by n data values which are integers.
Write a complete Java program, consisting of only a class and a main method to read this data and print for each line
the line number followed by the product of the positive data values if there are any,
otherwise the line number followed by zero.
For example, if the input data is
1. 4 5 -3 2 7
2. 5 1 -3 5 6 -80
3. 0
4. 1 -7
5. 2 6 -6
then your program would print
1. 70
2. 30
3. 0
4. 0
5. 6
- 10-20-2008, 07:55 PM #2
Similar Threads
-
Reading Integers from a text file
By tress in forum New To JavaReplies: 6Last Post: 02-26-2011, 05:45 PM -
Finding Median of X Integers
By Hasan in forum New To JavaReplies: 3Last Post: 08-12-2008, 02:06 PM -
[SOLVED] Integers (averages and remainders)...need help
By Zebra in forum New To JavaReplies: 4Last Post: 04-16-2008, 01:26 PM -
Java program that stores user inputs
By staticy2003 in forum Advanced JavaReplies: 6Last Post: 01-24-2008, 07:46 PM -
Random Integers
By www.kwalski.com in forum Java AppletsReplies: 8Last Post: 12-09-2007, 05:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks