(3) Write a program to store 5 of your friend’s names in an array.
1
Expert's answer
2011-08-07T07:19:21-0400
import java.io.*;
public class Task10 { public static void main(String[] args) throws IOException { & // Preparing the stream & BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
& // reading the names of the friends & String[] friendNames = new String[5]; & System.out.println("Enter the names of 5 your friends"); & for (int i = 0; i < 5; i++) & { & System.out.print("Enter the name of friend " + (i + 1) + ": "); & friendNames[i] = bReader.readLine(); & }
& // All names are stored in array & System.out.print("\nNow the array 'friendNames' stores 5 of your friend’s names"); } }
Comments
Leave a comment