所以,我正在制作一个基本的小费计算器,我需要知道如何将用户输入的15%,23%等改为0.15,0.23等。
这是我目前的代码:
import java.util.Scanner;
public class TipCalc {
public static void main(String args[]) {
Scanner meal = new Scanner(System.in);
double food, tax, tip, fin;
System.out.println("How much was the meal?");
food = meal.nextDouble();
System.out.println("How much was the tax?");
tax = meal.nextDouble();
System.out.println("How much would you like to tip? I recomend 15%");
tip = meal.nextDouble();
}
}
请帮忙!谢谢!
答案 0 :(得分:4)
double tip;
tip = meal.nextDouble() / 100;
或者
double tip = 15.0;
tip = tip / 100;
甚至
double tip = 15.0;
tip /= 100;
答案 1 :(得分:0)
如果您的提示输入为15。
使用
tip = meal.nextDouble() / 100.0;
System.out.println(tip);
输出:0.15