Re: why am I getting this error "varible temp1 might not have been initialized"
- From: "sandie" <amanda772007@xxxxxxxxx>
- Date: 25 Mar 2006 13:14:31 -0800
Roedy Green wrote:
On 25 Mar 2006 10:29:00 -0800, "sandie" <amanda772007@xxxxxxxxx>
wrote, quoted or indirectly quoted someone who said :
As of now, the program waits for me to enter something. What do I need
to do if the perosn just press enter key w/o putting a float value. And
a string vale? How do I let the program contiue to run so that I can
assing the default value?
What happens when you do that? Do you get 0, a null, a empty string,
an exception? Find out.
How to find out when the program doesn't continue? Using the debugger?
Is there a simpler approach at this stage?
My problem is how to grab what is not entered as for float and string.
Then put in code to detect that condition andI know how to do this part but how to make the program take empty
either issue and error message and
string and continue to execute is my problem.
repeat the question or assume some default value.
I want to compare what is not put by if statement but I do not know the
syntax and so I tried this and got error "incomparable type".
float temp2;
Scanner keyboard2 = new Scanner(System.in);
System.out.println("Enter a float value with 2 decimal position for
a temperature.");
if ((keyboard2.nextFloat())!= null)
temp2 = 0;
else
temp2 = keyboard2.nextFloat();
It doesn't like testing with null for float. What should I use
instead if null?
- - - - - - -
I did the following for scale and it compiles but when execute, the
program sits and waits for input.
System.out.println("Enter one character for degree scale (C or F).");
String strScale2;
if ((keyboard2.next())==null)
strScale2="C";
else
strScale2 = keyboard2.next();
char scale2 = (strScale2.toUpperCase()).charAt(0);
So I am stuck.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- Follow-Ups:
- References:
- why am I getting this error "varible temp1 might not have been initialized"
- From: sandie
- Re: why am I getting this error "varible temp1 might not have been initialized"
- From: Roedy Green
- Re: why am I getting this error "varible temp1 might not have been initialized"
- From: sandie
- Re: why am I getting this error "varible temp1 might not have been initialized"
- From: Roedy Green
- why am I getting this error "varible temp1 might not have been initialized"
- Prev by Date: Re: the meaning of 'this'
- Next by Date: Re: why am I getting this error "varible temp1 might not have been initialized"
- Previous by thread: Re: why am I getting this error "varible temp1 might not have been initialized"
- Next by thread: Re: why am I getting this error "varible temp1 might not have been initialized"
- Index(es):
Relevant Pages
|