Results 1 to 6 of 6
Thread: java homework help
- 09-22-2009, 07:44 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
- 09-22-2009, 07:53 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Read about System.out.printf.
- 09-22-2009, 07:57 PM #3
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
will you check my code please and tell me if its right
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.text.NumberFormat;
public class CH3EX1{
public static void main(String[] args) throws IOException{
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter a decimal number.");
String input = console.readLine();
double decimal = Double.parseDouble(input);
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMaximumFractionDigits(2);
formatter.setMinimumFractionDigits(2);
System.out.println("Result:");
System.out.println(formatter.format(decimal));
System.exit(0);
}
}
- 09-22-2009, 08:08 PM #4
i think you can do it like this but not sure, for you to figure out how...
rounding double to two decimal places
u can use the import java.util.Scanner; function to give your user the right to enter someting and read it.
have fun,
Dieter
- 09-22-2009, 08:09 PM #5
ow your in a console app, my bad then.
We don't use that at school. We use the System.out.println
my bad then
all the best,
Dieter
- 09-22-2009, 08:12 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Having trouble with java homework...
By purinlove88 in forum New To JavaReplies: 3Last Post: 03-02-2009, 03:02 PM -
Java homework please
By Indulgence in forum New To JavaReplies: 1Last Post: 11-03-2008, 02:48 AM -
LF: Homework help with Java
By excurssion in forum New To JavaReplies: 2Last Post: 10-17-2008, 06:00 AM -
I need help with my java servlet homework(average)
By jellyfish888 in forum Java ServletReplies: 2Last Post: 12-23-2007, 09:57 PM -
Help with my java servlet homework
By jellyfish888 in forum Java ServletReplies: 2Last Post: 12-21-2007, 05:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks