File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes very basic java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "very basic java" Watch "very basic java" New topic
Author

very basic java

william roberts
Greenhorn

Joined: Sep 25, 2001
Posts: 3
I've just started a java correspondence course, and my tutor is away for a week, so please can anyone give me guidance on how to write the program shown below.
I'm trying to learn, so guidance only please, not a line by line solution.
"write a program which prompts the user to enter a sequence(I take this to be a very simple sequence, say 1-10) of 10 integers which are summed and the total displayed. Negatives are ignored i.e not summed and no more than ten numbers(including any negatives may be entered."
I speak java with all the fluency of a two year old, so single syllable replies.
dw milsom
Greenhorn

Joined: Sep 06, 2001
Posts: 1
Hi William,
i am fairly new to the language myself, so hopefully my answer won't sound like gobbledygook.
the command line input is an array of strings [ie. the args[] in public static void main(Sting[] args) ].
you'd need a loop to go through the array, determine if each number [ie. args[0], args[1], etc] is a non-negative, then add it to the sum. Then you just print it out!
I hope this makes sense...:-)
-d
[This message has been edited by dw milsom (edited September 25, 2001).]
[This message has been edited by dw milsom (edited September 25, 2001).]
John Kilbourne
Ranch Hand

Joined: Aug 22, 2001
Posts: 30
Start with what you do know:
1.Prompt the user: (possibly involves "println()"
2.Receive input: from comamnd line, this will be obtained from the args[] array of strings -
"public static void main(String [])"
args[3] would return the fourth string entered by the user at the command line, becoause indexing starts at args[0].
You need to convert the String to an int: (possibly involves a static method from the Integer class)
and so on...
Fred Abbot
Ranch Hand

Joined: Jun 01, 2000
Posts: 300
System.in();
is how you get keyboard input
if you use args the user cannot be prompted
so
- start the program print to the console
please enter a number
get that number repeat for 10 numbers
add up the numbers print the total

Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
William you might want to have a look at the Cattle Drive. If you select the individual assigments you see there are quite a basic tutorials/examples that teaches you the basics to solve the assignments.
Off course you can always dfecide to take the Cattle drive but pse read About the Cattle Drive

Good luck learning Java
Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
Hi William,
You might find the following code useful for getting user's response.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String strStringEnteredByUser = br.readLine();
Your need to put input java.io.*; in your import statements at the top.
Mahesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: very basic java