JAVA基础复习(三)

时间:2021-03-15 11:14:00   收藏:0   阅读:0

Java流程序控制

用户交互Scanner

public class Demo01 {
    public static void main(String[] args) {
        //创建一个扫描对象,用于接受键盘数据
        Scanner scanner = new Scanner(System.in);
        //判断用户是否输入字符
        if (scanner.hasNext()){
            //使用next方法接受
            String str = scanner.next();
            System.out.println("输出的内蓉为:"+str);
        }
        //凡是属于IO流的类如果不关掉会一直占用资源,要养成用完关掉的习惯
        scanner.close();
    }
}
public class Demo02 {
    public static void main(String[] args) {
        //从键盘接受数据
        Scanner scanner = new Scanner(System.in);
        System.out.println("使用nextLine方法接受:");
        //判断是否输入
        if(scanner.hasNextLine()){
            String str = scanner.nextLine();
            System.out.println("输出的内蓉为:"+str);
        }
        //关闭IO流
        scanner.close();

    }
}

顺序结构

选择结构

循环结构

break & continue

练习

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!