有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java格式,大小数,请按百分比计息

有人能解释一下它的用法吗?我真的很想知道怎么做。这是我使用Java的第二个月,请解释Java格式的用法。非常感谢你。我真的很感激。请随意问关于C++或Python的其他问题。我在格式,大小数的使用和如何设置需要帮助


import java.util.*;

import java.math.BigDecimal;

import java.text.NumberFormat;

import java.math.*;


public class Main{
    public static void main(String[] args)
    {

        Scanner myCalculation = new Scanner(System.in);

        System.out.print("Welcome to the Interest Calculator \n\n");
        String option = "y";
        while (option.equalsIgnoreCase("y"))
        {

            System.out.print("Enter Loan Amount: ");
            //double loanAmount = 520000;
            double loanAmount = myCalculation.nextDouble();
            //Get Interest rate from user
            System.out.print("Enter Interest Rate: ");
            // double interRate = .05375;
            double interRate = myCalculation.nextDouble();


            double interest = loanAmount * interRate;

            System.out.printf("%.3f", interest);
            System.out.println();


            //prompt user to continue? if he enter y then it will Continue
            //else it will stop
            //System.out.println("Continue? (y:n): ");
            Scanner scan = new Scanner(System.in);
            boolean stop = false;    
            while(!stop) {
            //do whatever
                System.out.println("Would you like to continue? (yes or no)");
                String s = scan.nextLine();
                if(s.equals("no")) {
                    stop = true;
                }
            }

        }
    }
}

共 (1) 个答案

  1. # 1 楼答案

    Scanner in = new Scanner(System.in);
    System.out.print("enter double");
    double d = in.nextDouble(); //doubles
    System.out.print("enter int");
    int i = in.nextInt(); //ints
    
    System.out.print("enter text");
    String text = in.next(); //gets a string up to the first space
    in.nextLine();
    System.out.print("enter text w/ spaces");
    String line = in.nextLine(); //gets a string up to the first space
    
    System.out.println(d);
    System.out.println(i);
    System.out.println(text);
    System.out.println(line);
    in.close();
    
    System.out.println(new DecimalFormat("#.###").format(4.567346344634));