| | |
Initialization Error
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 5
Reputation:
Solved Threads: 0
This is my code
Errors:
variable num11 might not have been initialized
variable num22 might not have been initialized
import java.lang.Math;
import java.io.*;
public class TestDfunction {
static void fun(float num1, float num2) throws IOException
{
BufferedReader read = new BufferedReader( new InputStreamReader(System.in));
String strNum1, strNum2;
System.out.print("Enter the first number: ");
strNum1 = read.readLine();
num1 = Float.parseFloat(strNum1);
System.out.print("Enter the second number: ");
strNum2 = read.readLine();
num2 = Float.parseFloat(strNum2);
}
static void menu()
{
System.out.println("Please choose the type of operation needs to be computed by pressing the corresponding number: ");
System.out.println("----------------------------------------------------------------------------------------------");
System.out.println(" 1. Addition");
System.out.println(" 2. Subtraction");
System.out.println(" 3. Multiplication");
System.out.println(" 4. Division");
System.out.println(" 5. Remainder");
System.out.println(" 6. Minimum");
System.out.println(" 7. Maximum");
System.out.println("----------------------------------------------------------------------------------------------");
}
public static void main(String[] args)
{
menu();
try{
BufferedReader read = new BufferedReader( new InputStreamReader(System.in));
float num11, num22;
String strChoose;
int choose;
strChoose = read.readLine();
choose = Integer.parseInt(strChoose);
System.out.println("");
while ((choose <1) || (choose >8))
{
System.out.println();
System.out.println("The number you have entered is invalid...");
menu();
strChoose = read.readLine();
choose = Integer.parseInt(strChoose);
}
switch (choose)
{
case 1:
fun(num11,num22);
System.out.println("The sum is: "+ (num11 + num22));
break;
case 2:
fun(num11,num22);
System.out.println("The diferrence is: " + (num11 - num22));
break;
case 3:
fun(num11,num22);
System.out.println("The product is: " + (num11 * num22));
break;
case 4:
fun(num11,num22);
System.out.println("The quotion is: " + (num11 / num22));
break;
case 5:
fun(num11,num22);
System.out.println("The remainder is: " + Math.IEEEremainder(num11,num22));
break;
case 6:
fun(num11,num22);
System.out.println("The smaller value is: " + Math.min(num11,num22));
break;
case 7:
fun(num11,num22);
System.out.println("The greater value is: " + Math.max(num11,num22));
break;
case 8:
System.exit(0);
}
}
catch (IOException e) {System.out.println("IO Error");}
}
}Errors:
variable num11 might not have been initialized
variable num22 might not have been initialized
The error is pretty self explanatory. You never gave the variables a value.
That creates them but it does not initialize them with a value. If you give them a starting value, such as zero, your error is fixed; however your program does not work due to a logic error. Your method fun reads the values but never returns them. I think you should be able to figure it out from there.
java Syntax (Toggle Plain Text)
float num11, num22;
Last edited by jasimp; Oct 11th, 2008 at 11:29 am.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
![]() |
Similar Threads
- Data type initialization error (C++)
- Win XP stop error (Windows NT / 2000 / XP)
- New object initialization error (C++)
- msurl.exe DLL Initialization failed (Viruses, Spyware and other Nasties)
- MS Visual++ 6.0 - Error C2146, C2501 ... (C++)
- HELP!! comp froze and when i restarted it was blank! (Troubleshooting Dead Machines)
- Error Linking KeyLogger.exe (C++)
Other Threads in the Java Forum
- Previous Thread: list
- Next Thread: Data retrive
Views: 1111 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool keyword linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






