I need help with some code. . . .
yo, I got a little bit of a problem, I try to write a program but I get an enoying error. I'm from sweden so the lang of the code is in swedish.
Here's da code:
public class Ex{
public static void main(String[] args){
boolean fortsatt = true;
double radie, l鋘gd, volym, h鰆d, bredd;
final double PI = 3.14159;
do{
System.out.println("MENY\n");
System.out.println("1.Klot");
System.out.println("2.R鋞block");
System.out.println("3.Cylinder");
System.out.println("4.Avsluta");
System.out.print("Ge ditt val: ");
char val = Keyboard.readChar();
switch(val){
case '1':
System.out.print("Ange radie: ");
radie = Keyboard.readDouble();
volym = 4*PI*radie*radie*radie/3;
break;
case '2':
System.out.print("Ange l鋘gd: ");
l鋘gd = Keyboard.readDouble();
System.out.print("Ange bredd: ");
bredd = Keyboard.readDouble();
System.out.print("Ange h鰆d: ");
h鰆d = Keyboard.readDouble();
volym = l鋘gd*bredd*h鰆d;
break;
case'3':
System.out.print("Ange radie: ");
radie = Keyboard.readDouble();
System.out.print("Ange h鰆d: ");
h鰆d = Keyboard.readDouble();
volym = PI*radie*radie*h鰆d;
break;
case '4':
fortsatt = false;
break;
default:
System.out.println("Fel");
}
if (val == '1' || val == '2' || val == '3'){
System.out.println("Volymen blir " + volym);
System.out.println("");
}
}while (fortsatt);
}
}
--
I get an error in line 44,System.out.println("Volymen blir " + volym);
Someone know what to do? I'm grateful to ant help I can get, Thx
[1766 byte] By [
arnadaa] at [2007-10-3 4:17:33]

D:\My Documents\Skola\Java\Program\omvandlare\Ex.java:44: variable volym might not have been initialized
System.out.println("Volymen blir " + volym);
^
1 error
Tool completed with exit code 1
sorry i'm a newbie, here is the error message and case 4 is the Exit function.
If I change theSystem.out.println("Volymen blir " + volym);
toSystem.out.println("Volymen blir " + "volym");
the program will work but it will not give any results of our calculations. . . Sorry my bad english !
import java.io.*;
public class Ex{
public static void main(String[] args){
boolean fortsatt = true;
double radie=0.0, langd=0.0, volym=0.0, hojd=0.0, bredd=0.0;
final double PI = 3.14159;
do{
System.out.println(" MENY\n");
System.out.println("1. Klot");
System.out.println("2. Ratblock");
System.out.println("3. Cylinder");
System.out.println("4. Avsluta");
System.out.print("Ge ditt val: ");
try{
char val =(char)System.in.read();
switch(val){
case '1':
System.out.print("Ange radie: ");
radie = (double)System.in.read();
volym = 4*PI*radie*radie*radie/3;
break;
case '2':
System.out.print("Ange langd: ");
langd = (double)System.in.read();
System.out.print("Ange bredd: ");
bredd = (double)System.in.read();
System.out.print("Ange hojd: ");
hojd = (double)System.in.read();
volym = langd*bredd*hojd;
break;
case'3':
System.out.print("Ange radie: ");
radie = (double)System.in.read();
System.out.print("Ange hojd: ");
hojd = (double)System.in.read();
volym = PI*radie*radie*hojd;
break;
case '4':
fortsatt = false;
break;
default:
System.out.println("Fel");
}
if (val == '1' || val == '2' || val == '3'){
System.out.println("Volymen blir " + volym);
System.out.println("");
}
}
catch(IOException e){
e.printStackTrace();
}
}while (fortsatt);
}
}
Try it and make appropriate changes in your code
U2601a at 2007-7-14 22:19:11 >
