Hey everyone- I'm new here and this is my first forum post so I hope this is in the right place!
I would appreciate all the help I can get:
I'm trying to make a Java code to find the volume of a sphere but can't seem to use the user's input because I'm getting an error that "keyboard.readLine()" does not represent a real integer. I've attached my code below - I'm sure it's poorly written but I wouldn't know how to properly write it until I fix the input problem- I'd like to use the user's input in the volume equation which follows- thanks everyone!
import java.io.*; // Stores information between user and computer.
public class VolumeOfSphere
{
public static void main (String[] args) throws IOException
{
String radius;
DataInputStream keyboard = new DataInputStream(System.in);
System.out.println("What is the radius of the sphere: ");
radius = keyboard.readLine();
volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 );
System.out.println("The volume of the sphere is: " + volume);
}
}