Okay, so I’m making a program and I want to take an input for a license plate # (Numbers and Letters) and what I’m looking to do is, take the input in one line, and be able to separate the Numbers and Letters in the input into two different variables, one Int and one String.
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();
...
I want to assign the numbers from the input to the int and keep the characters in the string plate?
What would be the way I can do this?
Any help is greatly appreciated.
You usually use regex for these types of things. Have a look at Java regex (http://docs.oracle.com/javase/tutorial/essential/regex/)