Computer Applications
Write a Java program to store the runs scored by 11 Indian cricket players in an innings along with their names. Now display the name of the cricketer who has made the highest score in that innings along with the runs.
Java
Java Arrays
26 Likes
Answer
import java.util.Scanner;
public class KboatCricketScore
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
final int PLAYERS = 11;
int runs[] = new int[PLAYERS];
String names[] = new String[PLAYERS];
for (int i = 0; i < PLAYERS; i++) {
System.out.println("Enter player " + (i + 1) + " name:");
names[i] = in.nextLine();
System.out.println("Enter player " + (i + 1) + " score:");
runs[i] = in.nextInt();
in.nextLine();
}
int highScoreIdx = 0;
for (int i = 1; i < PLAYERS; i++) {
if (runs[i] > runs[highScoreIdx])
highScoreIdx = i;
}
System.out.println("Highest Scorer");
System.out.println(names[highScoreIdx] + "\t" + runs[highScoreIdx]);
}
}Output

Answered By
7 Likes
Related Questions
Name the below structure:

- One dimensional array
- Two Dimensional array with 4 rows and 5 columns
- Three dimensional array
- Two Dimensional array with 5 rows and 4 columns
Write a Java program to store n numbers in an one dimensional array. Pass this array to a function number(int a[]). Display only those numbers whose sum of digit is prime.
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.