scanner

Posted hapyygril

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scanner相关的知识,希望对你有一定的参考价值。

package mypro01;
import java.util.Scanner;
/**
 * 测试scanner类,如何接受键盘的输入 
 * @author 4090039qrh
 * @version 10.0.2
 */

public class TestScanner {
    
    /**
     * 键盘输入字符串
     */
    public static void test01() {
        Scanner s = new Scanner(System.in);
        String str = s.next();//next会等待键盘的输入字符串
        System.out.println("输入:"+str);
        
    }
    
    
    public static void test02() {
        Scanner s = new Scanner(System.in);
        System.out.print("加数: ");
        int a = s.nextInt();//nextInt会等待输入整数
        System.out.print("加数: ");
        int b=s.nextInt();
        int sum = a+b;
        System.out.println("和为:"+sum);
    }
    
    public static void main(String[] args) {
        test01();
        test02();
        
    }
    
    

}

 

以上是关于scanner的主要内容,如果未能解决你的问题,请参考以下文章

第三次过程性考核

白盒测试之静态代码扫描:SonarQube+Scanner环境搭建及使用

白盒测试之静态代码扫描:SonarQube+Scanner环境搭建及使用

java基础程序代码及Scanner和Random

持续代码质量管理-SonarQube Scanner部署

Java 代码在 Scanner hasNextLine 处挂起