0

String [] name = {"IIman bt Zulkifli", "Ismaalif b Ismail", "Katherine Kong", "M.Mirunaaleeni", "Khalish b Ismail", "Younis b Ahmad", "Syifa Hani bt Shahizam", "Atiyyah bt Fahmi", "Furqan b Hafizi", "Qarnur Asraf b Ali"};

    for(int no = 1; no<=10; no ++)
    System.out.println(no + ".");

    for(int i = 0; i < name.length; i++)
    System.out.println(name[i] + " ");

this is an example of the output :

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

IIman bt Zulkifli

Ismaalif b Ismail

Katherine Kong

M.Mirunaaleeni

Khalish b Ismail

Younis b Ahmad

Syifa Hani bt Shahizam

Atiyyah bt Fahmi

Furqan b Hafizi

Qarnur Asraf b Ali

HOW CAN I DISPLAY THE NAMES BESIDE THE NUMBER ?

3 Answers 3

2

Try this way

for(int i = 0; i < name.length; i++)
System.out.println((i+1) +". "+ name[i] );

update

Note: Please ensure name and marks arrays length are equal

for(int i = 0; i < name.length; i++)
    System.out.println((i+1) +". "+ name[i] +" : " +marks[i] );
Sign up to request clarification or add additional context in comments.

Comments

1
 for(int i = 0; i < name.length; i++)
    System.out.println( (i+1) + "." + name[i] );

should do

Comments

1
for(int i = 0; i < name.length; i++) {
    System.out.printf("\d: %s\n", i+1, name[i]);
}

1 Comment

i should be i + 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.