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




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 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.

.



Relevant Pages

  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... to strcmpwhich expects a pointer to a string. ... And now a question about something else: why do you use floating ... int,float, char, etc. ...
    (comp.lang.c)
  • Re: inconsistent behavior of >FLOAT
    ... empty string, strings with leading and trailing blanks. ... I think it is too late for>FLOAT to rescind the strong suggestion in its spec that this "should" be the case. ... As long as the spec is tightened to require that a string of blanks must be treated as a valid zero, a programmer would know to filter such a case, if needed, before it is passed to>FLOAT. ... I think ignoring leading and trailing blanks may be reasonable for>FLOAT, as long as it does not violate the current spec. ...
    (comp.lang.forth)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... And now a question about something else: why do you use floating ... use then to copy a float into a char *1. ... binary representation doesn't resemble a string like "123.46343" ...
    (comp.lang.c)
  • Re: How to marshall "pointer to pointer"
    ... UInt16 Layer, ByteInstanceName, float X, float Y, BytePath, IntPtr ... DstPath); ... IntPtr and pass it it Marshal.PtrToStringBSTR() to get this string. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: help with Table Macro
    ... Available Float, which will always be in column ... string contained in that cell. ... test phrase "available float". ... next matching word and repeat the process until no more matching words ...
    (microsoft.public.word.application.errors)