J
J
javanub2014-05-24 22:11:37
Java
javanub, 2014-05-24 22:11:37

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

2 answer(s)
Q
qizer, 2014-05-25
@javanub

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);

that is, your logic began to sound a little different: if not zero came, then output

S
Sergey Shcherbakov, 2014-05-24
@nesh_nedvin

if (vol > 0) System.out.println(vol);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question