美文网首页
Java学习第四天

Java学习第四天

作者: a04b20daaf33 | 来源:发表于2016-12-01 20:33 被阅读0次
  • 分支语句
    if(){
    }
    else if(){
    }
    else
import java.util.Scanner;

public class Test01 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入年份: ");
        System.out.println("请输入月份");
        int year = input.nextInt();
        int month = input.nextInt();
        if (year > 0 && month > 0 && month <= 12){
            int day;
            if (month == 2){
                if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
                    day = 29;
                }
                else{
                    day = 28;
                }
            }
            else if (month == 4 | month == 6 | month == 9 | month == 11){
                day = 30;
            }
            else{
                day = 31;
            }
            System.out.println(year + "年" + month + "月" + "有" + day + "天");
        }
        else {
            System.err.println("输入错误");
        }
        input.close();

    }

}
switch(){               // 整数,字符,枚举,字符串
 }
  case 1:
  break;
  case 2:
  break;
  default:
  break;
import java.util.Scanner;

public class Test02 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入月份: ");
        int month = input.nextInt();
        String wordOfMonth;
        switch (month) {
        case 1:
            wordOfMonth = "January";
            break;
        case 2:
            wordOfMonth = "February";
            break;
        case 3:
            wordOfMonth = "March";
            break;
        case 4:
            wordOfMonth = "April";
            break;
        case 5:
            wordOfMonth = "May";
        case 6:
            wordOfMonth = "June";
            break;
        case 7:
            wordOfMonth = "July";
            break;
        case 8:
            wordOfMonth = "August";
            break;
        case 9:
            wordOfMonth = "September";
            break;
        case 10:
            wordOfMonth = "October";
            break;
        case 11:
            wordOfMonth = "November";
            break;
        case 12:
            wordOfMonth = "December";
            break;
            
        default:
            wordOfMonth = "输入错误";
            break;
        }
        System.out.println(wordOfMonth);
        input.close();

    }

}
  • 循环语句
    while(){
    }

public class Test05 {

    public static void main(String[] args) {
        int i = 1;
        while(i <= 10){
            System.out.println(i + ". Hello,world!");
            i += 1;
        }
        System.out.println("循环结束");

    }

}

  do{
   }  while();
public class Test07 {

    public static void main(String[] args) {
        int i = 0;
        int sum = 0;
            do {
                i += 1;
                sum += i;
            } while (i < 100);
        System.out.println(sum);
        System.out.println("循环结束");

    }

}

相关文章

  • java学习day04-方法和数组

    java学习第四天内容总结: 学习内容: 关注公众号:java进阶架构师,获取的学习视频 总结: 1、java...

  • 2018-08-18

    java学习第四天之HTML-Servlet 观看慕课网后写的一些笔记 什么是Servl...

  • Java学习第四天

    练习:求任意数的绝对值: 一:语句: 语句: 以分好结尾的就是一条语句。 分类: 空语句和单条语句,复合语句:...

  • 学习Java第四天

    方法:程序中完成独立功能,可重复使用的一段代码的集合 方法定义格式: 【修饰符】 返回值的类型 方法名称(形式参数...

  • Java学习第四天

    分支语句if(){}else if(){}else 循环语句while(){}

  • java 学习第四天

    面向对象的特征二:继承 关键字super this和super的区别 面向对象特征三: 多态 instanceof...

  • NLP幸福人生初级班(5.27)

    第四天学习中……

  • 参数传递--java学习第四天

    栈:对象的引用;局部变量(参数属于局部变量)(main方法中的属性属于局部变量;方法的形参属于局部变量) 堆:ne...

  • 全新Java学习完整路线图

    Java教程,Java学习,Java学习路线图,全新Java学习路线图! 深知广大爱好Java的人学习是多么困难,...

  • 2018-01-19

    彩铅学习第四天

网友评论

      本文标题:Java学习第四天

      本文链接:https://www.haomeiwen.com/subject/xycfmttx.html