Answer the question
In order to leave comments, you need to log in
How to make System.out.print() not output when false
There is a usual check for 0. If a == 0, then output Fail. But in main when I drive in the parameters, it displays both Fail and the value. How to rewrite the code correctly?
class Round{
double a;
double b;
double x;
public double roundFi(double a, double b){
if(a == 0){
roundMs();
}
return x = a * b;
}
public void roundMs(){
System.out.println("Fail");
}
}
public class Main{
public static void main(String[] args){
Round ne = new Round();
double vol = ne.roundFi(0, 3); /*Параметры метода*/
System.out.println(vol); /*Как сделать, чтобы если приходит 0 vol не выводилось*/
}
}
Answer the question
In order to leave comments, you need to log in
nesh_nedvin,
I think it would be more correct to do this:
instead of the line
it is necessary to withdraw
if (vol != 0)
System.out.println(vol);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question