0
我有一項任務,要求我們輸入我們最喜歡的餐廳和地址。我無法在同一行上獲得打印出來的地址。java餐廳地址顯示不正確
import java.util.Scanner;
public class Restaurant {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
String name;
System.out.print("Enter your Favorite Restaurant: ");
name = user_input.next();
String street;
System.out.print("Enter the Street Address: ");
street = user_input.next();
String city;
System.out.print("Enter the City: ");
city = user_input.next();
String state;
System.out.print("Enter the State: ");
state = user_input.next();
String zip;
System.out.print("Enter the Zip Code: ");
zip = user_input.next();
String restaurant = name + "\n" + city + ", " + state + ", " + " " " + zip;"
+ "";
}
}
我得到一個輸出,不讓我輸入正確的整個地址。必須有一個更簡單的方法來做到這一點。
Enter your Favorite Restaurant: Uncle Bubs
Enter the Street Address: Enter the City: 444 Spender St
Enter the State: Enter the Zip Code: BUILD SUCCESSFUL (total time: 19 seconds)
舉一個例子輸入和輸出,所以我們可以明白你的意思 – jgr208
逃亡'「'爲」 \那麼它可能工作。如果你想在同一行上,那麼刪除'\ n'。使用'System.out.println' – Nilesh
@Nilesh:我想你的意思是'\「' – sinclair