Computer Science, asked by ashamishra170pci228, 1 year ago

how to type two decimal places in java? ex- INPUT - 12.367 OUTPUT - 12.37 WITHOUT USING MATH CLASS


ashamishra170pci228: plz its urgent

Answers

Answered by nitish8089
0

code....
public class Program
{
public static void main(String[] args) {
double x=12.367;
int a=(int)(x*100);
int temp=a;
do{
int y=a%10;
if(y>5){
a+=1;
}
else if(y<5){
a-=1;
}
else{
temp/=10;
y=temp%10;
if(y%2==0){
a+=1;
}
else{
a=a;
}
}
}while(false);
x=(a/100.0);
System.out.println(x);
}
}

nitish8089: some customisation do yourself to make code...
Similar questions
Math, 6 months ago