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]
# 1

What error?

If it is at compile time I am betting it is complaining that variable may not have been defined. Which is correct, since case 4 does not define it and and it is not defined when it is declared. Define it to 0.0 under case 4.

But this is only a wild guess as you have not told us what the error is.

masijade.a at 2007-7-14 22:19:11 > top of Java-index,Java Essentials,Java Programming...
# 2

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 !

arnadaa at 2007-7-14 22:19:11 > top of Java-index,Java Essentials,Java Programming...
# 3

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 > top of Java-index,Java Essentials,Java Programming...
# 4
Then read my previous post and replace "may not have been defined" with "may not have been initialized". Then perform the change suggested, and everything should be okay. Alternatively, you can set the value of that valriable to 0.0 at the spot where you declare it.
masijade.a at 2007-7-14 22:19:11 > top of Java-index,Java Essentials,Java Programming...