We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My code is not working. Its not reading the input properly can any one help me on this...
lass Calculate{
final Display output =new Display();
public int get_int_val() throws IOException {
int number =0;
Scanner sc=new Scanner(System.in);
if(sc.hasNextInt()){
number = sc.nextInt();
}else{
sc.close();
}
return number;
}
public double get_double_val() throws IOException{
double number =0;
Scanner sc=new Scanner(System.in);
if(sc.hasNextDouble()){
number = sc.nextDouble();
}
return number;
}
public static Calculate do_calc(){
return new Calculate();
}
public double get_volume(int a){
if(a <= 0){
throw new NumberFormatException("All the values must be positive");
}else{
DecimalFormat df = new DecimalFormat("#.000");
return Double.parseDouble(df.format(a * a * a));
}
}
public double get_volume(int l, int b, int h){
if(l <= 0 || b <= 0 || h <= 0){
throw new NumberFormatException("All the values must be positive");
}else{
DecimalFormat df = new DecimalFormat("#.000");
return Double.parseDouble(df.format(l * b * h));
}
}
public double get_volume(double r){
if(r <= 0){
throw new NumberFormatException("All the values must be positive");
}else{
DecimalFormat df = new DecimalFormat("#.000");
return Double.parseDouble(df.format((2/3)*3.14159265*(r*r*r)));
}
}
public double get_volume(double r, double h){
if(r <= 0 || h <=0 ){
throw new NumberFormatException("All the values must be positive");
}else{
DecimalFormat df = new DecimalFormat("#.000");
return Double.parseDouble(df.format(3.14159265*(r * r * h)));
}
}
}
class Display{
public void display(double volume){
System.out.println(volume);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Calculating Volume
You are viewing a single comment's thread. Return to all comments →
My code is not working. Its not reading the input properly can any one help me on this...
lass Calculate{
}
class Display{
}