Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        5年前关闭。
                    
                
        

因此,我正在制作一个基本的小费计算器,我需要知道如何将用户输入的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();
    }
}


请帮忙!谢谢!

最佳答案

double tip;
tip = meal.nextDouble() / 100;


要么

double tip = 15.0;
tip  = tip / 100;


甚至

double tip = 15.0;
tip /= 100;

10-02 03:14