java_program 8

 Practical Name: write a java program to accept details of 'n' criket players (p id,p name ,total runs , innings played, not out times)calculate of all the players display the details of player having maximum average


 

import java.util.Scanner;

public class PlayerDemo{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

final int PLAYERS = 2;

int runs[] = new int[PLAYERS];

String names[] = new String[PLAYERS];

int TimesNotOut []=new int[PLAYERS];

int InningsPlayed  []=new int[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) +" Times Not Out");

TimesNotOut [i]=in.nextInt();

System.out.println("Enter player "+ (i + 1) +" Innings Played");

InningsPlayed[i]=in.nextInt();

System.out.println("Enter player " + (i + 1) +" Total Runs:");

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("the details of player having maximum average");

System.out.println("Name     Total Run     Times Not Out     Innings Played");

System.out.println(names[highScoreIdx] + "     \t" + runs[highScoreIdx]+ "             \t" +TimesNotOut[highScoreIdx]+ "               \t" +InningsPlayed[highScoreIdx]);

}

}




Post a Comment

Previous Post Next Post