Import java.util.Scanner; public class ScannerDemo { public static void main (String [] args) { Scanner Scan = new new Scanner (the System.in); // keyboard data received from // the received character string next mode System.out. println ( "next receiving mode:" ); // determines whether there is an input iF (scan.hasNext ()) { String str1 = scan.next (); System.out.println ( "data input is:" + str1 ); } scan.close (); } }
Import java.util.Scanner; public class ScannerDemo { public static void main (String [] args) { Scanner Scan = new new Scanner (the System.in); // keyboard data received from // the received character string nextLine embodiment System.out. println ( "nextLine reception mode:" ); // determines whether there is an input iF (scan.hasNextLine ()) { String str2 = scan.nextLine (); System.out.println ( "data input is:" + str2 ); } scan.close (); } }
Import java.util.Scanner; public class ScannerDemo { public static void main (String [] args) { Scanner Scan = new new Scanner (the System.in); // keyboard data received from int I = 0 ; a float F = 0.0f ; of System.out.print ( "enter an integer:" ); iF (scan.hasNextInt ()) { // determines whether the input is an integer of I = scan.nextInt (); // receiving integer System.out.println ( "integer data: "+ I); }the else { // input error information System.out.println ( "input is not an integer!" ); } of System.out.print ( "Input Decimal:" ); IF (scan.hasNextFloat ()) { // Analyzing input the fractional whether F = scan.nextFloat (); // receiving decimal System.out.println ( "fractional data:" + F); } the else { // input error information System.out.println ( "do not enter decimal "! ); } scan.close (); } }
Import java.util.Scanner; class ScannerDemo { public static void main (String [] args) { Scanner Scan = new new Scanner (the System.in); Double SUM = 0 ; int m = 0 ; the while (scan.hasNextDouble ()) { Double X = scan.nextDouble (); m = m +. 1 ; SUM = SUM + X; } System.out.println (m + "and the number of" + SUM); System.out.println (m + "is the average number of" + (sum / m)); scan.close(); } }