Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: can someone tell me if this looks right??

1. ## can someone tell me if this looks right??

these are the instructions that i was given

Write a program that calculates the area of a circle from its radius. The radius will be an integer entered via the keyboard.
Use this formula : area = PI * radius2
You will need to use the constant PI which you get by using Math.PI
A sample run would look like this :
Enter radius : 3
The radius is : 3
The area is : 28.274333882308138

when i try to run the program nothing happens??

cross posted, thanks
can someone tell me if my program looks right?? - Java Forums

```import java.util.Scanner;

public class Assign1_Roberts{
public static void main(String[]args){
Scanner input = new Scanner(System.in);
//Prompt the user for input
final double PI = 3.14159;//Declare a constant

double radius = input.nextInt();

//Compute area
double area = radius * radius * PI;

System.out.println("Enter radius :" + input.nextInt());
System.out.println("The radius is : " + radius);
System.out.println("The area is: " + area);

}
}```

2. ## Re: can someone tell me if this looks right??

double radius = input.nextInt();
In this line you are asking for input from the user.

//Compute area
double area = radius * radius * PI;
in this line you are calculating the area.

System.out.println("Enter radius :" + input.nextInt());
If you have already taken radius as input , then why you are asking for input in this line too.

3. ## Re: can someone tell me if this looks right??

+Rep for pointing out the cross post.

4. ## Re: can someone tell me if this looks right??

alright here is my updated code..and my out put will be posted at the bottom...getting the correct results just tell me if I am on the right track thanks

```import java.io.*;
public class Assign1_Roberts{
public static void main(String[] args){
double radius = 0;
try{
System.out.println("Enter Radius  : ");
System.out.println("The Area is : "+area);

}
catch(Exception e){
System.out.println("Error : "+e);
}
}
}```