aspose file tools*
The moose likes Beginning Java and the fly likes Help with this code. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with this code." Watch "Help with this code." New topic
Author

Help with this code.

Rush Art
Greenhorn

Joined: Oct 17, 2009
Posts: 7
Hello, I just can't figure it out what is wrong with this code of mine. Especially at System.out.println . The intention is, the code reads three whole numbers from the user. And it write the lowest number entered, then the higest, the sum of all three, and then the product of all those three. The answer is shown in each line.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to JavaRanch

You are using + before you have turned the entries into numbers. So entry 1 = 12, entry 2 = 34 and entry 3 = 56. Then you will (successfully) try to convert the String "123456" into a number.

Use int not Integer if you are doing arithmetic. Remember an int cannot be null.

Go through your two if statements with a pencil and paper, and see whether any of the conditions is true, and follow the execution. Don't write an if statement as a single line: format it like this, noting the indentation spaces and {} braces:There is more . . .

But good luck with that ( ). Correct tiny bits of code, then you can probably see what is happening with the rest of it.
Rush Art
Greenhorn

Joined: Oct 17, 2009
Posts: 7
Aha,I see it now. But how can I make it read "en and to and tre "separately??
I can't just:



Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
No, you can't say int tall three times. You would have to give three different names to the different numbers.
Rush Art
Greenhorn

Joined: Oct 17, 2009
Posts: 7
Managed it. But it became a long code.... Is there any way to shorten it?

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Well done so far

Yes, you can shorten it. The numbers min and max should be ints not Integers.

Write down on a piece of paper what the smallest number is when you get to the first number. Then see how much you can see beyond that point.

Tiny little bits, one step at a time. That's how you do it.
 
jQuery in Action, 2nd edition
 
subject: Help with this code.