老师要求的用户界面显示结果如下:
This program computes the total cost of a purchase. Enter the price of the purchased item. 12.50
Enter how many items are purchased? 3
The final cost of the purchase with the 7% tax applied is $40.125
以下是我的代码:
package jave.util;
import java.util.Scanner;
public class Assignment1 {
public static void main(String[] args) {
System.out.println("Please input the number");
Scanner N= new Scanner(System.in);
System.out.println("Please input the price");
Scanner P= new Scanner(System.in);
int number=N.nextInt();
double price=P.nextDouble();
double cost= (price*number*1.07);
System.out.println("The final cost of the purchase with the 7% tax applied is " + cost);
// TODO Auto-generated method stub
}
}
此时我输入数值的时候,两个数值是连续输入的,请问怎么编写才能令输入一个数值之后,再提示输入另外一个?(另外代码有什么可以优化的地方也请知道一下)