当前位置: 首页 > news >正文

Day05-C:\Users\Lenovo\Desktop\note\code\JavaSE\Basic\src\com\David\struct-ifDemo01~03+shunxuDemo

Scanner

Java.util.scanner

Scanner s = new Scanner(System.in);

Next

  1. 一定要读取到有效字符才结束
  2. 对输入有效字符前的空白,next()方法会自动将其去掉
  3. 只有输入有效字符后才将其后面输入的空白作为分隔符或结束符
  4. next()不能得到带有空格的字符串

Nextline

  1. 以Enter为结束符,也就是说Nextline()方法返回的是输入回车之前的所有字符
  2. 可以获得空白

顺序结构

选择结构

  1. if单选择 if(布尔表达式){}
  2. if双选择结构 if(布尔表达式){}else{}
  3. if多选择结构 if(布尔表达式1){}else if(布尔表达式2){}else if (布尔表达式3){}else{}//有一个满足的话,整个语句就结束,一个if必须跟着至少一个else,有一个else if为true 会跳过其他else if
  4. 嵌套的if结构//最难的
    package com.David.struct;

public class shunxuDemo {
public static void main(String[] args) {
System.out.println("hello1");
System.out.println("hello2");
System.out.println("hello3");
System.out.println("hello4");
System.out.println("hello5");
}

}
package com.David.struct;

import java.util.Scanner;

public class ifDemo01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个内容");
String s = scanner.nextLine();
if(s.equals("Hello")){//判断字符串是否一致
System.out.println("Hello");
}
System.out.println("End");

    scanner.close();
}

}
package com.David.struct;

import java.util.Scanner;

public class ifDemo02 {
public static void main(String[] args) {
//考试分数大于六十分就是及格,否则就是不及格
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩");
int score = scanner.nextInt();
if(score >=60){
System.out.println("及格");
}else {
System.out.println("不及格");
}

    scanner.close();}

}
package com.David.struct;

import java.util.Scanner;

public class ifDemo03 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("请输入您的成绩");
int score = scanner.nextInt();
if(score==100){//一个if必须跟着至少一个else,有一个else if为true 会跳过其他else if
System.out.println("满分");
}else if(score<100&&score>=90){
System.out.println("A级");
} else if(score<90&&score>=80){
System.out.println("B级");
} else if(score<80&&score>=70){
System.out.println("C级");
} else if(score<70&&score>=60) {
System.out.println("D级");
}else if(score<60&&score>=0) {
System.out.println("成绩不合格");
}else{
System.out.println("成绩不合法");
}

    scanner.close();
}

}

http://www.zskr.cn/news/9319.html

相关文章:

  • Codeforces Round 1052 (Div. 2)
  • PatternMatcher-Pytorch
  • uboot启动流程
  • 内存泄漏
  • Context Engineering
  • github/网盘/公众号信息收集
  • AtCoder Regular Contest 206 (Div. 2) 部分题解
  • Influxdb 得模糊查询总结
  • 多表关系和多表查询
  • 【反比例函数】【做题笔记】【图形存在性】题目合集
  • 20250920 嘉定江桥---江苏吴江区太湖 往返160KM骑行小记
  • 工作队列(Work Queues)与消息确认(Ack)
  • 6-5 汇聚层
  • 6-4 多输入多输出通道
  • 6-2图像卷积
  • 基于WOA鲸鱼优化的XGBoost序列预测算法matlab仿真
  • Arch下实现人脸识别登录:howdy的配置与使用
  • Winform的Formborder.None情况下,解决不能拖动的问题
  • 实用指南:centos sshd:xxx.xxx.xxx.xxx:allow 如何设置
  • fedora无法看视频?编解码器详细安装教程
  • 高并发高吞吐量
  • 服务降级
  • 镜像制作
  • IAR Embedded Workbench中的MCU启动过程分析
  • CSP-S 2025
  • ENVI系列教程(七)——自定义 RPC 资料图像正射校正
  • Linux 笔记本充电限制【转发】
  • 别样的CSP-S初赛大战(又名:我和油一的那些年)
  • 范德蒙德卷积入门
  • 用 【C# + WinUI3 + 图像动画】 来理解:高数 - 函数 - 初等函数 - 行人-