class simple {
public static void main() {
double n, m;
Scanner ip = new Scanner(System.in);
n = ip.nextDouble();
m = ip.nextDouble();
m = n * m;
System.out.println("Value in " + m);
}
}
In the above code.. My output should only use decimal poinf if my input is using decimal point, rest of the time it should print like an integer.
Ex : INPUT : 2 , 3
--> OUTPUT : Value is 6
INPUT : 2.1, 1
--> OUTPUT : Value is 2.1
So my question is.... How can i print my number (with decimal point, without decimal point) according to my input?
You can use
NumberFormat
; the #-sign mean that decimals are only shown if they're non-zero.