I want to read from the keyboard the first name and last name of a member separated by space I have tried the following but it doesn't work.

public static void updateWeight()
    {
        Scanner in = new Scanner(System.in); // Creation of a new Scanner object
        String tempName = ""; // Store temporary name collected by Scanner objecgt
        String tempLastName = ""; // Store temporary last name collected by Scanner object
        boolean found = false; // Boolean value in the case tha a member is found
        int i = 0;
        
        //Message to be displayed on the screen to input the values of tempName and tempLastName
        System.out.println(" Give first name and last name separated with a  (space) of the member you want to change the weight.");
        String input = in.nextLine();
        String delims = "[ }";
        String tokens = input.split(delims);
        tempName = in.next();
        tempLastName = in.next();
incompatible types

String tokens = input.split(delims);

Thanks for any help.

I want to read from the keyboard the first name and last name of a member separated by space I have tried the following but it doesn't work.

public static void updateWeight()
    {
        Scanner in = new Scanner(System.in); // Creation of a new Scanner object
        String tempName = ""; // Store temporary name collected by Scanner objecgt
        String tempLastName = ""; // Store temporary last name collected by Scanner object
        boolean found = false; // Boolean value in the case tha a member is found
        int i = 0;
        
        //Message to be displayed on the screen to input the values of tempName and tempLastName
        System.out.println(" Give first name and last name separated with a  (space) of the member you want to change the weight.");
        String input = in.nextLine();
        String delims = "[ }";
        String tokens = input.split(delims);
        tempName = in.next();
        tempLastName = in.next();
incompatible types

String tokens = input.split(delims);

Thanks for any help.

Im not sure what this is ment to do"

String delims = "[ }";

but if you want to split a string by a whitespace do:

input.split(" ");

Its too simple
String.split("(Space)") // Leave a space here ... Second split function returns a String array so u need a String array to carry the values.... Like

String a[] = String.Split(" ");

And then print them or use them for ur logic...

Hope this Help....

Java has methods, not functions.
The split() method starts with s not S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.