- package prac6;
- public class PlayerDemo {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Player p1=new Player(11,"Rohit",34,200,false);
- Player p2=new Player(12,"sachin",40,350,true);
- Player p3=new Player(13,"dhoni",39,280,true);
- Player p4=new Player(14,"sevag",41,290,true);
- Player p5=new Player(15,"kohli",32,300,false);
- Player[] pList=new Player[5];
- pList[0]=p1; pList[1]=p2;
- pList[2]=p3; pList[3]=p4;
- pList[4]=p5;
- Player[] rList=findSeniorPlayers(pList);
- for(int i=0;i<rList.length;i++)
- {
- System.out.println("Senior Name is "+ rList[i].getName()+ " and run is "+rList[i].getHighestRuns());
- }
- String[] snew=findTopPlayers(pList);
- System.out.println("top players are:");
- for(int i=0;i<snew.length;i++)
- {
- System. out.println(snew[i]);
- }
- }
- public static Player[] findSeniorPlayers(Player[] pList)
- {int count=0;
- for(int i=0;i<pList.length;i++)
- {
- if(pList[i].getAge()>35)
- {
- count++;
- }
- }
- Player[] tmp=new Player[count];
- int j=0;
- for(int i=0;i<pList.length;i++)
- {
- if(pList[i].getAge()>35)
- {
- tmp[j]=pList[i];
- j++;
- }
- }
- return tmp;
- }
- public static String[] findTopPlayers(Player[] pList)
- {
- int count=0;
- for(int i=0;i<pList.length;i++)
- {
- if(pList[i].getHighestRuns()>250)
- {
- count++;
- }
- }
- String[] tmp1=new String[count];
- int j=0;
- for(int i=0;i<pList.length;i++)
- {
- if(pList[i].getHighestRuns()>250)
- {
- tmp1[j]=pList[i].getName()+" : "+pList[i].getHighestRuns();
- j++;
- }
- }
- return tmp1;
- }
- }
[text] updatedprac6
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: