判断循环的用法 if switch
来源:互联网 发布:学校网络设计方案 编辑:程序博客网 时间:2024/06/05 23:05
public class TestWeek {
//需求:根据用户输入的数据给出指定的日期
// if小练习 构造方法
static void test01(int week){
if(week==1){
System.out.println(week+"对应的是星期一");
}
if(week==2){
System.out.println(week+"对应的是星期二");
}
if(week==3) {
System.out.println(week+"对应的是星期三");
}
if(week==4){
System.out.println(week+"对应的是星期四");
}
if(week==5){
System.out.println(week+"对应的是星期五");
}
if(week==6){
System.out.println(week+"对应的是星期六");
}
if(week==7){
System.out.println(week+"对应的是星期七");
}
else{
System.out.println("没有这一天");
}
}
static void test02(int month){
// if循环
if(month==3 || month==4 || month==5 ){
System.out.println(month+"月是春季");
}
else if(month==6 || month==7 || month==8){
System.out.println(month+"月是夏季");
}
else if(month==9 || month==10 ||month==11){
System.out.println(month+"月是秋季");
}
else if (month==12 || month==1 || month==2){
System.out.println(month+"月是冬季");
}
else{
System.out.println(month+"月不是季节");
}
}
/*swithc(表达式)
* case 取值1: {
* 执行语句
* }
* case 取值2: {
* 执行语句
* }
* byte short int char(四种数据选择类型)
*/
static void Test03(){
/*
* 用户随机输出数据对应 星期
* switch语句数据类型 int byte short char(常用)
*/
double a= Math.random();//随机类型用double
int b =(int)(a * 6)+1;
switch(b) {
case 1: {
System.out.println("今天是 星期一");
break;
}
case 2: {
System.out.println("今天是 星期二");
break;
}
case 3: {
System.out.println("今天是 星期三");
break;
}
case 4: {
System.out.println("今天是 星期四");
break;
}
case 5: {
System.out.println("今天是 星期五");
break;
}
case 6: {
System.out.println("今天是 星期六");
break;
}
case 7: {
System.out.println("今天是 星期天");
break;
}
default:
break;
}
}
public static void main(String [] args){
test01(8);
test02(13);
Test03();
}
}
//需求:根据用户输入的数据给出指定的日期
// if小练习 构造方法
static void test01(int week){
if(week==1){
System.out.println(week+"对应的是星期一");
}
if(week==2){
System.out.println(week+"对应的是星期二");
}
if(week==3) {
System.out.println(week+"对应的是星期三");
}
if(week==4){
System.out.println(week+"对应的是星期四");
}
if(week==5){
System.out.println(week+"对应的是星期五");
}
if(week==6){
System.out.println(week+"对应的是星期六");
}
if(week==7){
System.out.println(week+"对应的是星期七");
}
else{
System.out.println("没有这一天");
}
}
static void test02(int month){
// if循环
if(month==3 || month==4 || month==5 ){
System.out.println(month+"月是春季");
}
else if(month==6 || month==7 || month==8){
System.out.println(month+"月是夏季");
}
else if(month==9 || month==10 ||month==11){
System.out.println(month+"月是秋季");
}
else if (month==12 || month==1 || month==2){
System.out.println(month+"月是冬季");
}
else{
System.out.println(month+"月不是季节");
}
}
/*swithc(表达式)
* case 取值1: {
* 执行语句
* }
* case 取值2: {
* 执行语句
* }
* byte short int char(四种数据选择类型)
*/
static void Test03(){
/*
* 用户随机输出数据对应 星期
* switch语句数据类型 int byte short char(常用)
*/
double a= Math.random();//随机类型用double
int b =(int)(a * 6)+1;
switch(b) {
case 1: {
System.out.println("今天是 星期一");
break;
}
case 2: {
System.out.println("今天是 星期二");
break;
}
case 3: {
System.out.println("今天是 星期三");
break;
}
case 4: {
System.out.println("今天是 星期四");
break;
}
case 5: {
System.out.println("今天是 星期五");
break;
}
case 6: {
System.out.println("今天是 星期六");
break;
}
case 7: {
System.out.println("今天是 星期天");
break;
}
default:
break;
}
}
public static void main(String [] args){
test01(8);
test02(13);
Test03();
}
}
0 0
- 判断循环的用法 if switch
- if/switch/while/do while/for/等循环及判断的简要用法案例
- switch 循环中的判断 类型和if() 的判断类型
- if,switch语句的用法
- If 判断、switch语句和三中循环语句
- switch和if判断的个人理解
- if switch 具体用法 循环 while do while for
- if switch判断结构
- if;if else;if else if 循环结构的用法
- if else 与switch的区别 -switch用法
- if()else + switch用法
- if,switch,for循环语句
- c for循环嵌套switch的用法
- switch/while/if条件判断
- 不用那if,switch,?:语句判断两个数的大小
- if 判断 循环
- 循环+if判断
- 流程控制陷阱(Switch语句,标签,if语句,for循环,foreach循环的循环计数器)
- Postgresql uuid,pgtrashcan,pldebugger install
- @override 下划线
- autocomplete="off"
- 排列组合公式
- 16标准(键盘,控制台)输入输出流
- 判断循环的用法 if switch
- 更正swiprefreshlayout主动显示小圆圈
- 【流媒體】 Android 实时视频编码—H.264硬编码
- Log4j 2使用教程
- CodeForces 288A--贪心
- debug log
- 杭电oj 1096 A+B for Input-Output Practice (VIII)
- Imgproc_4_图像轮廓
- 基本数据类型与引用数据类型参数传递