好吧,所以我正在製作一個程序,我想爲一個牌照#(數字和字母)和我要做的是,將輸入作爲一行,並且能夠將輸入中的數字和字母分隔爲兩個不同的變量,一個是Int和一個String。Java,從字符串中取一個數字,並將它分配給一個單獨的變量 - Java
public class CarRental {
public static String model;
public static String plate;
public static int platenum;
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Car Model:");
model = input.nextLine();
System.out.println("License Plate: ");
plate = input.nextLine();
...
我想將輸入的數字賦給int並保留字符串中的字符? 我能做到這一點的方式是什麼? 任何幫助,不勝感激。
是否意味着# 「號」?如果是這樣,爲什麼不使用「號碼」?它只有5個字符長,並使您的問題可讀。 –
請給我們一個例子 - 它將更清晰地表明你的輸入看起來像 – amit
並且給出了你期望的輸出例子輸入,因爲那也不清楚。 –