Re: About to give up
- From: Arved Sandstrom <asandstromtwo@xxxxxxxxxxx>
- Date: Sun, 09 Mar 2008 18:17:21 GMT
KyoGaSuki wrote:
So finally it decided to actually PRINT something...and then IHere's the guts of a small test file I wrote up just now:
realized that it wasn't working how I needed it to. I am just ready
to give up completely considering it is due in an hour and a half and
I have managed to mess it all up. That, and the formatting won't
work, AND nothing is showing up in the output file. *is seriously
close to tears*:
**********
Scanner scanner = new Scanner(new File("test1.txt"));
float balance = 1000.00f;
while (scanner.hasNext()) {
int num = scanner.nextInt();
float amt = scanner.nextFloat();
balance -= amt;
System.out.printf("%3d\t%6.2f\n", num, balance);
}
scanner.close();
**********
The input file has an integer and a float on each line. A typical output
line (console) is:
4 848.93
Some thoughts on your code:
1. as others pointed out, why create the PrintWriter and not use it? No
surprise that nothing is going to a file;
2. the format descriptor for ints is 'd';
3. You're talking money here...why are 'balance' and 'deposit' not floats or
doubles?;
4. catch the FileNotFoundException and do something useful with it *in* your
app, even if at this stage you are just printing a message.
I'll assume that the format of your input file supports your Scanner
parsing.
AHS
--
* change 'two' to '2' to email me
.
- Follow-Ups:
- Re: About to give up
- From: Lew
- Re: About to give up
- References:
- About to give up
- From: KyoGaSuki
- About to give up
- Prev by Date: Re: BinaryTree
- Next by Date: JSP beans retrieval with a for loop
- Previous by thread: Re: About to give up
- Next by thread: Re: About to give up
- Index(es):
Relevant Pages
|