From 4b00d5838cb434ffa1a3abf75832f17cc0106450 Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Mon, 22 Apr 2024 23:44:03 +0800 Subject: [PATCH] fix bug --- ticket/Test.java | 7 ++++--- ticket/TicketSeller.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ticket/Test.java b/ticket/Test.java index 503ccec..1eb1dd1 100644 --- a/ticket/Test.java +++ b/ticket/Test.java @@ -11,7 +11,7 @@ public class Test { Scanner sc = new Scanner(System.in); while (continueBuy) { System.out.print("Please enter your name: "); - name = sc.next(); + name = sc.nextLine(); System.out.print("Please enter your payment: "); payment = sc.nextInt(); Thread consumer = new Thread(ts, name + "-" + payment); @@ -22,8 +22,9 @@ public class Test { e.printStackTrace(); } System.out.println("Do you want to continue buying tickets? Y: Yes, N: No"); - continueBuy = sc.next().equalsIgnoreCase("Y"); + continueBuy = "Y".equalsIgnoreCase(sc.next()); + sc.nextLine(); } sc.close(); } -} \ No newline at end of file +} diff --git a/ticket/TicketSeller.java b/ticket/TicketSeller.java index 8faa684..0c3a07b 100644 --- a/ticket/TicketSeller.java +++ b/ticket/TicketSeller.java @@ -71,4 +71,4 @@ public class TicketSeller implements Runnable { } } } -} \ No newline at end of file +}