Results 1 to 4 of 4
Thread: Need some help
- 09-30-2009, 06:54 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 5
- Rep Power
- 0
Need some help
I'm taking this as a class but i'm stuck
import java.util.*;
public class Sort3 {
public static Scanner in = new Scanner (System.in);
public static void main (String [] args) {
System.out.println (GetDouble());
double a = GetDouble();
double b = GetDouble();
double c = GetDouble();
}
public static double GetDouble() {
System.out.print ("Enter a double: ");
double x = GetDouble ();
return x;
}
}
When i run this it prints out "Enter a double:" hundreds of times and a dont know y. I need to be able to have GetDouble Ask 3 sperate times so i can get a,b, and c. ???
Also on a side note how would i check to make sure they entered a valid double??
- 09-30-2009, 08:12 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Why have you started a new thread for this problem?
In double x = GetDouble ();, your GetDouble method is calling itself.
Read the API specs for the Scanner class to find out how to use it.
- 09-30-2009, 10:15 AM #3
1.Put ur requirement in a paper and then try to implement.See u are agaian and again calling GetDouble() results to infinite printouts.
2.Gothru the api.
I have modified ur code to understand the things much better.
import java.util.*;
Java Code:public class Test { public static Scanner in = new Scanner (System.in); public static void main (String [] args) { double a = GetDouble(); double b = GetDouble(); double c = GetDouble(); } public static double GetDouble() { System.out.print ("Enter a double: "); [B]double x = in.nextDouble ();[/B] return x; } }Ramya:cool:
- 09-30-2009, 11:08 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks