Posts

Showing posts with the label java scanner

Write a java program for a cricket player The program should accept the details from user (max 10): Player code, name, runs, innings- played and number of times not out.

Write a java program for a cricket player The program should accept the details from user (max 10): Player code, name, runs, innings- played and number of times not out. The program should contain following menu: -Enter details of players. -Display average runs of a single player. -Display average runs of all players. (Use array of objects & function overloading) import java.io.*; class Player { String Name; int TotalRuns, TimesNotOut, InningsPlayed,pcode; float Avg; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); void getData() { try { System.out.println("Enter Player Code: "); pcode=Integer.parseInt(br.readLine()); System.out.println("Enter Player Name: "); Name = br.readLine(); System.out.println("Enter Total Runs: "); Tot...

Scanner in Java

Scanner is used in JAVA to accept the values from the user through the Standard I/O devices. Below is a basic program to demonstrate the use of scanner : import java.util.Scanner; public class scan { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Enter any string"); String a=s.nextLine(); System.out.println("String is :"+a); } }  OUTPUT : Enter any string codeground String is :codeground