I've just started with Java and so I'm doing plenty of mistakes, I've solved and understood many of them, but now I'm having problems with input. I saw that there are two kinds of input: InputBufferedReader and Scanner, but I read that the first is better (I don't know why yet), so I' m using that.
The error that I get is:
Code
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Cerchio{
private float r;
private float area;
private float cfr;
final double pi = 3.14;
public static void main(String[] args){
System.out.println("Programma cerchio\n");
Cerchio cerchio = new Cerchio();
cerchio.getR();
cerchio.c_cfr();
cerchio.c_area();
System.out.println("La circonferenza è: " + cerchio.cfr);
System.out.println("L area è: " + cerchio.area);
}
private float getR(){
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader num = new BufferedReader(input);
try{
String sr = num.readLine();
r = Float.valueOf(sr).floatValue();
} catch(NumberFormatException nfe){
System.out.println("Incorrect!!!");
}
return r;
}
private float c_cfr(){
cfr =(float)(2 * pi * r); //casting
return cfr;
}
private float c_area(){
area = (float)(pi * (r*r));
return area;
}
}
Probably there are other mistackes, but I don't know how to go over this one.
What's wrong? Thank you!
PS: I read this but I didn't understand why and how that works