import java.util.Scanner;
public class Exercise12 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("Please enter your full name:");    
        String input = s.nextLine();
        int space1 = input.indexOf(' '); 
        String fname = input.substring(0,space1);
        System.out.println(fname);
    }
}
            Asked
            
        
        
            Active
            
        
            Viewed 37 times
        
    -1
            
            
         
    
    
        Cristian Greco
        
- 2,566
- 1
- 19
- 24
 
    
    
        1XCoderX1
        
- 27
- 1
- 5
1 Answers
0
            Have a look at the split() method for Strings.
String[] tokens = input.split(" ");
 
    
    
        Cristian Greco
        
- 2,566
- 1
- 19
- 24