zoukankan      html  css  js  c++  java
  • java学习第42天2020/8/16

    一.

    import java.util.Scanner;
    public class time {
    	int year,month,day;
    	time()
    	 {
    		  year=1000;month=1;day=1;
    	 }
    	public int isleap()
    	{
    	 if(year%400==0||year%100!=0&&year%4==0)
    	  return 1;
    	 else return 0;
    	}
    	public int check()
    	{
    		if(month<=12)
    		 {
    		  if((month==2&&isleap()==1&&day<=29)||(month==2&&isleap()==0&&day<=28)||((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&day<31)||(month==4||month==6||month==9||month==11&&day==30))
    		   return 1;
    		  else
    		   return 0;
    		 }
    		 else
    		  return 0;
    	}
    	 public void setdate(int j,int k,int l)
    	 {
    	  year=j;
    	  month=k;
    	  day=l;
    	 }
    	 public void display()
    	 {
    	  if(check()==0)
    		  System.out.println(year+"-"+month+"-"+day+","+"error day");
    	  else
    	   {
    		  System.out.println(year+"-"+month+"-"+day);
    	      if(isleap()==1)
    	    	  System.out.println(","+"leap day");
    	      else
    	    	  System.out.println(","+"common year");
    	   }
    	 }
    	 public static void main(String []args)
    	 {
    		 Scanner input=new Scanner(System.in);
    		 time r=new time();
    		 System.out.println("请输入两组年月日:");
    		 int a,b,c,d,e,f;
    		 a=input.nextInt();b=input.nextInt();c=input.nextInt();d=input.nextInt();e=input.nextInt();f=input.nextInt();
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(a,1,1);
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(a,b,1);
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(a,b,c);
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(d,e,f);
    		 r.isleap();
    		 r.check();
    		 r.display();
    	 }
    
    }
    

     

    二.输出后都会换行

    使用System.out.println输出换行使用System.out.print输出不换行

    package 例题;
    import java.util.Scanner;
    public class time {
    	int year,month,day;
    	time()
    	 {
    		  year=1000;month=1;day=1;
    	 }
    	public int isleap()
    	{
    	 if(year%400==0||year%100!=0&&year%4==0)
    	  return 1;
    	 else return 0;
    	}
    	public int check()
    	{
    		if(month<=12)
    		 {
    		  if((month==2&&isleap()==1&&day<=29)||(month==2&&isleap()==0&&day<=28)||((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&day<31)||(month==4||month==6||month==9||month==11&&day==30))
    		   return 1;
    		  else
    		   return 0;
    		 }
    		 else
    		  return 0;
    	}
    	 public void setdate(int j,int k,int l)
    	 {
    	  year=j;
    	  month=k;
    	  day=l;
    	 }
    	 public void display()
    	 {
    	  if(check()==0)
    		  System.out.println(year+"-"+month+"-"+day+","+"error day");
    	  else
    	   {
    		  System.out.print(year+"-"+month+"-"+day);
    	      if(isleap()==1)
    	    	  System.out.println(","+"leap day");
    	      else
    	    	  System.out.println(","+"common year");
    	   }
    	 }
    	 public static void main(String []args)
    	 {
    		 Scanner input=new Scanner(System.in);
    		 time r=new time();
    		 System.out.println("请输入两组年月日:");
    		 int a,b,c,d,e,f;
    		 a=input.nextInt();b=input.nextInt();c=input.nextInt();d=input.nextInt();e=input.nextInt();f=input.nextInt();
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(a,1,1);
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(a,b,1);
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(a,b,c);
    		 r.isleap();
    		 r.check();
    		 r.display();
    		 r.setdate(d,e,f);
    		 r.isleap();
    		 r.check();
    		 r.display();
    	 }
    
    }
    

     

    三.例题

  • 相关阅读:
    JavaScript 实现深度拷贝
    JacaScript arguments
    EMACS 使用入门
    ubuntu 14.04 nginx + mysql + php源码安装
    c语言 头文件
    程序员技术练级攻略
    if和switch的选择
    .htaccess (分布式配置文件)
    yii2 windows 安装过程
    Js 冒泡事件阻止
  • 原文地址:https://www.cnblogs.com/qiangini/p/13583348.html
Copyright © 2011-2022 走看看