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.
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, args, 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).]
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 would return the fourth string entered by the user at the command line, becoause indexing starts at args. You need to convert the String to an int: (possibly involves a static method from the Integer class) and so on...
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
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
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com