In: Computer Science
Source Code:
Output:
Code in text format (See above images of code for indentation):
import java.util.*;
/*class definition*/
public class LastnameFirstname10
{
/*main method*/
public static void main(String[] args)
{
/*Scanner object to read data from the user*/
Scanner read=new Scanner(System.in);
/*declare two arrays*/
String[] names=new String[5];
String[] grades=new String[5];
/*read data into arrays*/
System.out.println("Enter student names and their grades:");
for(int i=0;i<5;i++)
{
/*read name from user and store it in names array*/
System.out.print("Name: ");
names[i]=read.nextLine();
/*read grade from user and store it in grades array*/
System.out.print("Grade: ");
grades[i]=read.nextLine();
}
/*print contents of array*/
System.out.println("Name\tGrade");
for(int i=0;i<5;i++)
System.out.println(names[i]+": "+grades[i]);
}
}