Scanner N = new Scanner(System.in);
Scanner P = new Scanner(System.in); // ❌ 多餘,同一輸入流無需多實例
int number = N.nextInt();
double price = P.nextDouble(); // 連續讀取,無提示間隔
Scanner sc = new Scanner(System.in);
System.out.println("Please input the number");
int number = sc.nextInt(); // 讀取整數,換行符留在緩衝區
System.out.println("Please input the price");
double price = sc.nextDouble(); // 直接讀取下一個 double
System.out.println("The final cost ... is $" + (price * number * 1.07));
Scanner 實例複用 System.in;nextInt() 後緩衝區剩餘換行符,nextDouble() 會自動跳過空白字符(含換行),無需額外處理;若需讀取整行字符串(含空格),在 nextInt() 後調用一次 sc.nextLine() 清空換行符,再用 nextLine() 讀取文本。