JAva~Scanner(数字:scanner.nextInt()文字列:scanner.next())

1837 ワード

1)メモ
1)Scanner(    )
  (1)syso               ,    ;
  (2)Scanner      :         :
	      ,      ,     ,     ,     ,  jdk     ;
	 jdk api       ; 
  (3)System.in
  	          、  、        ;
  	  System.in      ;

  	  int num = scanner.nextInt();  //                  Int    :35     
  	  String str = scanner.next();  //              ,          

2)Random(       )

3)ArrayList(      ,      )

4)sun 1.6         ;
    -->  ;

5)8        +    
	String: 
	          ,        ,          ,      ,    JDK     ;

6)API  3 
    
        (1,2,3    )
      (   ,  )-->     ,           ,          ;

7)       
	  :
		import    .   ;
		     ,    ;
		  java.lang          ;

	  :
		       = new    ();

	  :
		   .    ();

8)   :            ,      ;
	   nextInt():
		         
		       

例1
package com.itcast.day07;

import java.util.Scanner;

public class Demo01Scanner {
    public static void main(String[] args) throws Exception{
        Scanner scanner = new Scanner(System.in);
        
        int num = scanner.nextInt();
        System.out.println(num);

        String str = scanner.next();
        System.out.println(str);
    }
}

例2
package com.itcast.day07;

import java.util.Scanner;

public class Demo02ScannerSum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("    1   :");
        int a = sc.nextInt();

        System.out.println("    2   :");
        int b = sc.nextInt();

        System.out.println("    3   :");
        int c = sc.nextInt();

//        System.out.println("    :" + (a + b));

        int temp = a > b ? a : b;
        int max = temp > c ? temp : c;
        System.out.println("   =" + max);
    }
}