Как именно здесь, сделать сокращение после запятой ???
public class JavaApplication1 {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here System.out.print("Введите количество литров: "); Scanner scan = new Scanner(System.in); double l = scan.nextDouble(); double i,f,w,y; double a = 3,b = 2,c = 1,x = 1; i = a / 3; f = b / 3; w = c / 3; y = x / 3;
if(l>0) { i = i * l; f = f * l; w = w * l; y = y * l; } else { System.out.println("Количество литров не может быть равным 0 или отрицательным"); System.exit(0); } System.out.printf("Ложек соли = " + i); System.out.println("Ложек сахара = " + f); System.out.println("Лавровых листов = " + w); System.out.println("Время = " + y); } }
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.print("Введите количество литров: ");
Scanner scan = new Scanner(System.in);
double l = scan.nextDouble();
double i,f,w,y;
double a = 3,b = 2,c = 1,x = 1;
i = a / 3;
f = b / 3;
w = c / 3;
y = x / 3;
if(l>0)
{
i = i * l;
f = f * l;
w = w * l;
y = y * l;
}
else
{
System.out.println("Количество литров не может быть равным 0 или отрицательным");
System.exit(0);
}
System.out.printf("Ложек соли = " + i);
System.out.println("Ложек сахара = " + f);
System.out.println("Лавровых листов = " + w);
System.out.println("Время = " + y);
}
}