For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2006 > Re: why am I getting this error "varible temp1 might not have been initialized&q









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: why am I getting this error "varible temp1 might not have been initialized&q
sandie

2006-03-25, 10:02 pm


Roedy Green wrote:
> On 25 Mar 2006 10:29:00 -0800, "sandie" <amanda772007@yahoo.com>
> wrote, quoted or indirectly quoted someone who said :
>
>
> 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 and
> either issue and error message and

I know how to do this part but how to make the program take empty
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.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com