Computing.Net > Forums > Programming > Using java input loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Using java input loop

Reply to Message Icon

Name: mambofatale
Date: April 20, 2009 at 07:57:23 Pacific
OS: N/A
Subcategory: Java
Comment:

Hi! I'm taking my first java class, and am having a hard time with the latest homework assignment. I'm to use an input on loop so the user enters a series of numbers. These numbers in turn need to be used to print out their banking transactions (very basic, just anything that was positive will be a deposit, anything they entered as negative will show as a withdrawal.) The problem is with the "balance" - how do I get a user input to correlate in terms of sums on the balance print out, if I didn't ask for each transaction separately (with a different variable)?

Here's my code so far:


import java.util.Scanner; // program uses class Scanner
public class x {

//main method

public static void main( String args[] ){

// create scanner

Scanner input = new Scanner(System.in);

int i = input.nextInt();

while (i != 0){

for (i = 1; i <=10; i++){

System.out.print("\nFirst enter your balance, transactions for the last 30 days and end with 0:");
i = input.nextInt();

if (i == 0)
break;
}
}
}
}

How do I use each input in a printf statement? Or am I totally off the mark here?

Thanks!

P.S. I also realized that it's not reading my for count either. hmmm...



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Using java input loop

java for loops www.computing.net/answers/programming/java-for-loops/12866.html

Sine wave generation using Java www.computing.net/answers/programming/sine-wave-generation-using-java/12012.html

Read MS Access using Java program www.computing.net/answers/programming/read-ms-access-using-java-program/3986.html