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

     

    三.例题

  • 相关阅读:
    [转载]从零开始学习OpenGL ES之一 – 基本概念
    ios中陀螺仪CoreMotion的使用
    如何在IOS中使用3D UI – CALayer的透视投影
    cocos3d加载3Dmax模型到ios中
    cocos2d 坐标系统参考
    PAT 1029 Median
    PAT 1028 List Sorting
    Linux中的进程调度(二)
    LaTeX学习(一)
    搬家
  • 原文地址:https://www.cnblogs.com/qiangini/p/13583348.html
Copyright © 2011-2022 走看看