Ok, so I know this is a noob question but I am having trouble getting this code to work. What the code is supposed to do is give you the diamter when you input the radius. I know my code is probably butchered but what am I doing wrong and why because I am trying to learn.
import java.util.Scanner;
public class Circle{
Scanner dd = new Scanner(ystem.in);
System.out.println("Whats is the radius?");
double r = dd.nextDouble();
public Circle(double r){
radius = r;
}
public double diameter(){
double d = radius * 2;
return d;
}
}
public class Tester{
public static void main(String args[]){
Circle cir1 = new Circle(35.5);
System.out.println(Circle.diameter)
}
}
You must put you code in a method. This block will cause an error :
Next, in your main, you do Circle cirl = new Circle(35.5) and on the next line, you call Circle.diameter. You should call the diameter from you new instance as so cirl.diameter().
You could try something like this instead