jeudi 21 septembre 2017

How to get input the first name in java

How to get First Name Friend But here I want to take the first name even though its input there is a last name with spaces

Example : First friend

I Input the name : Alvin Indra

Second Friend

I Input the name : Redi Rusmana

And output :

Alvin

Redi

Please help me Syntax :

package latihan;

import java.util.Scanner;

public class LatihanArray {
    public static void main(String[] args) {
        String name,class,age;
        int many;
        String[] friend = new String[100];
        Scanner sc = new Scanner(System.in);
        Scanner scx = new Scanner(System.in);

        System.out.print("Name  : ");
        name = sc.nextLine();
        System.out.print("Class : ");
        class = sc.nextLine();
        System.out.print("Age  : ");
        age = sc.nextLine();

        System.out.print("Enter How Many Friends : ");
        many = sc.nextInt();
        for(int i=0;i<n;i++){
            System.out.print("Friend Of-"+(i+1)+" : ");
            friend[i] = scx.nextLine();
        }
        System.out.print("\n");
        System.out.println("Initials : ");
        for(int i=0;i<many;i++){
            System.out.println((i+1)+". "+friend[i].charAt(0));
        }
        System.out.print("\n");
        System.out.println("4 Letterhead : ");
        for(int i=0;i<n;i++){
            System.out.println((i+1)+". "+friend[i].substring(0,4));
        }
        System.out.println("First Name : ");
        for(??????){
            if(??????){
               for(????????){
                  ???????????????;
               }
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire