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();
    	 }
    
    }
    

     

    三.例题

  • 相关阅读:
    (转)使用 PyInstaller 把python程序 .py转为 .exe 可执行程序
    (转)使用 python Matplotlib 库绘图
    使用Matplotlib画图系列(一)
    Numpy常用金融计算(一)
    Windows中安装Linux子系统的详细步骤
    Centos7+Postfix+Dovecot实现内网邮件收发 风行天下
    centos7系统防火墙端口转发 风行天下
    Centos7+Postfix+Dovecot实现内网邮件收发
    centos7的路径含有空格Linux命令使用时路径存在空格、特殊符号(如、@等等) 风行天下
    zabbix无法使用Detect operating system [zabbix] 风行天下
  • 原文地址:https://www.cnblogs.com/qiangini/p/13583348.html
Copyright © 2011-2022 走看看