Results 1 to 7 of 7
Thread: Can someone help me out on this?
 10112012, 12:37 AM #1Member
 Join Date
 Oct 2012
 Posts
 35
 Rep Power
 0
Can someone help me out on this?
Trying to create a java program that will allow me to enter the Radius of a circle in cmd console window and will calculate the area of the circle but I KEEp getting error messages!! Can someone tell me where I'm going wrong??
import java.util.Scanner;
public class Circle
{
public static void main(String[]args)
{
double Radius, pi = 3.14;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the Radius of the Circle: ");
Radius = Double();
Double Result;
Result = (Radius * Radius) * (pi);
System.out.print("The total area is: " + Result);
}
}
 10112012, 12:57 AM #2Member
 Join Date
 Oct 2012
 Posts
 7
 Rep Power
 0
Re: Can someone help me out on this?
Here you go, try this one.
Java Code:import java.util.Scanner; public class Circle { public static void main(String[]args) { double pi = 3.14; Scanner keyboard = new Scanner(System.in); System.out.print("Enter the Radius of the Circle: "); double radius = Integer.parseInt(keyboard.nextLine()); double result = (radius * radius) * (pi); System.out.print("The total area is: " + result); } }
double radius = Integer.parseInt(keyboard.nextLine()); < this takes your input, converts it to type int, and stores it in a variable called radius.
From this point, the next variable, result, just holds the answer which is shown in the finals System.out.print
 10112012, 01:03 AM #3Senior Member
 Join Date
 Oct 2012
 Posts
 176
 Rep Power
 4
Re: Can someone help me out on this?
Its the line Radius = Double();
I assume you were going for keyboard.nextInt(); wich will take the next number entered in the line.
Also I would suggest that next time you enter code use the correct format of before you code put[ CODE] and after [/ CODE] just with no spaces
p.s. also to square a number you can use Math.pow(yourbase,yourExponente)
 10112012, 01:06 AM #4Member
 Join Date
 Oct 2012
 Posts
 35
 Rep Power
 0
Re: Can someone help me out on this?
Thanks so so much!!! Big help! :D However, you used Integer.parseInt, but this is for integers and I was going for doubles yet it STILL stores it as a double? How does it do that and not store it as an integer that you declared it as?
 10112012, 01:22 AM #5Member
 Join Date
 Oct 2012
 Posts
 7
 Rep Power
 0
Re: Can someone help me out on this?
double, long, int, etc all store the same type of data, a numerical value. The only difference between each of those variable declarations is the range in which the stored data must be in. I don't remember the exact ranges off the top of my head though
 10112012, 02:17 AM #6Java Apprentice
 Join Date
 Oct 2012
 Location
 On my computer
 Posts
 10
 Rep Power
 0
Re: Can someone help me out on this?
I thought you had to do "Double.parseInt". Also, I recommend using "Math.PI" in place of your pi double. ;)

Re: Can someone help me out on this?
You should be using
Java Code:double radius = Double.parseDouble(someString);
Java Code:double radius = Integer.parseInt(someString);
Rather than giving whole solutions, we much prefer to get the original poster's errors and try to have him work with *his* code towards a solution. This takes more work on your part, but in the end is usually much more satisfying for you, and a much better learning experience for the original poster.Last edited by Fubarable; 10112012 at 02:31 AM.
Bookmarks