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
Define a class to accept values into an integer array of order 4 x 4 and check whether it is a DIAGONAL array or not. An array is DIAGONAL if the sum of the left diagonal elements equals the sum of the right diagonal elements. Print the appropriate message.
Example:
3 4 2 5
2 5 2 3
5 3 2 7
1 3 7 1Sum of the left diagonal element = 3 + 5 + 2 + 1 = 11
Sum of the right diagonal element = 5 + 2 + 3 + 1 = 11
A single dimensional array has 50 elements, which of the following is the correct statement to initialize the last element to 100.
- x[51]=100
- x[48]=100
- x[49]=100
- x[50]=100
Consider the following program segment and answer the questions given below:
int x[][] = {{2,4,5,6}, {5,7,8,1}, {34, 1, 10, 9}};(a) What is the position of 34?
(b) What is the result of x[2][3] + x[1][2]?