Results 1 to 2 of 2
- 10-20-2008, 07:42 PM #1Member
- Join Date
- Oct 2008
- Rep Power
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
4. 1 -7
5. 2 6 -6
then your program would print
- 10-20-2008, 07:55 PM #2
- By tress in forum New To JavaReplies: 6Last Post: 02-26-2011, 06:45 PM
- By Hasan in forum New To JavaReplies: 3Last Post: 08-12-2008, 02:06 PM
- By Zebra in forum New To JavaReplies: 4Last Post: 04-16-2008, 01:26 PM
- By staticy2003 in forum Advanced JavaReplies: 6Last Post: 01-24-2008, 08:46 PM
- By www.kwalski.com in forum Java AppletsReplies: 8Last Post: 12-09-2007, 06:49 PM