In: Computer Science
Java Programming (8th Edition) Joyce Farrell p.530, Chapter 10 Problem 1E with user input with scanner and the following results:
Enter name of horse: ABC
Enter color of horse: Red
Enter year: 2000
Enter name of horse: DEF
Enter color of horse: Blue
Enter year: 2010
Enter number of races: 6
ABC is red and born in 2000.
DEF is blue and born in 2010.
DEF completed 6 races..
import java.util.*;
public class Main
{
public static void main(String[] args)
{
//string array declaration
String name[] = new String[10];
String color[] = new String[10];
int year[] = new int[10];
int races[] = new int[10];
//intput name, color, year and number of races
for(int i=0; i<2; i++)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter name of
horse: ");
name[i] = sc.nextLine();
System.out.print("Enter color of
horse: ");
color[i] = sc.nextLine();
System.out.print("Enter year:
");
year[i] = sc.nextInt();
System.out.print("Enter number of
races: ");
races[i] = sc.nextInt();
}
//display info on the computer screen
System.out.println("");
for(int i=0; i<2; i++)
{
System.out.println(name[i] + " is "+color[i]+" and
born in "+year[i]+".");
if(races[i]>0)
System.out.println(name[i] + " completed "+ races[i] +
" races..");
}
}
}
OUTPUT: