用java输入某年某月某日判断这是这一年的第几天用if完成 有没有大神帮我完成 ,这个程序有点小毛病还望帮忙改正,谢谢!!!

Waylon1 2018-04-18 11:30:36
import java.util.Scanner;
public class eight{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入年月日");
int a= sc.nextInt();
int b= sc.nextInt();
int c= sc.nextInt();
int s=0;
if(b>2&&a%4==0&&a%100!=0||a%400==0){
System.out.println(c+(b-1)*31-((b-2)/2)-2+1);
}
else{
if(b<3)
System.out.println(c+(b-1)*31);
if(b>=3)
System.out.println(c+(b-1)*31-((b-2)/2)-2);
}
}
}
...全文
829 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
疼碍 2018-04-23
  • 打赏
  • 举报
回复
Calendar 日期计算类 了解下
「已注销」 2018-04-20
  • 打赏
  • 举报
回复
Scanner sc = new Scanner(System.in);
System.out.println("请输入年月日");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
Calendar cal = Calendar.getInstance();
cal.set(a, b, c);
int d = cal.get(Calendar.DAY_OF_YEAR);           
System.out.println(d);
Waylon1 2018-04-19
  • 打赏
  • 举报
回复
引用 1楼yjsl__ 的回复:
public class eight {
	public static void main(String[] args) {
		while(true) {
			Scanner sc = new Scanner(System.in);
			System.out.println("请输入年月日");
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int s = 0;
			int m2 = 0;
			if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
				m2 = 29;
			else
				m2 = 28;

			s+=c;
			if(b>=2)
				s+=31;
			if(b>=3)
				s+=m2;
			if(b>=4)
				s+=31;
			if(b>=5)
				s+=30;
			if(b>=6)
				s+=31;
			if(b>=7)
				s+=30;
			if(b>=8)
				s+=31;
			if(b>=9)
				s+=31;
			if(b>=10)
				s+=30;
			if(b>=11)
				s+=31;
			if(b>=12)
				s+=30;
			System.out.println(s);
		}
		
	}
}
大哥 不要用12个if好不好
maradona1984 2018-04-19
  • 打赏
  • 举报
回复

import java.util.Scanner;

public class Test {

	public static void main(String[] args) {
		while (true) {
			Scanner sc = new Scanner(System.in);
			System.out.println("请输入年月日");
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int s = 0;
			int[] monthDays = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
			s += c;
			for (int i = 0; i < b - 1; i++) {
				int days = monthDays[i];
				if (i == 1 && (a % 4 == 0 && a % 100 != 0 || a % 400 == 0))
					days = 29;
				s += days;
			}
			System.out.println(s);
		}
	}

}
yjsl__ 2018-04-18
  • 打赏
  • 举报
回复
public class eight {
	public static void main(String[] args) {
		while(true) {
			Scanner sc = new Scanner(System.in);
			System.out.println("请输入年月日");
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int s = 0;
			int m2 = 0;
			if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
				m2 = 29;
			else
				m2 = 28;

			s+=c;
			if(b>=2)
				s+=31;
			if(b>=3)
				s+=m2;
			if(b>=4)
				s+=31;
			if(b>=5)
				s+=30;
			if(b>=6)
				s+=31;
			if(b>=7)
				s+=30;
			if(b>=8)
				s+=31;
			if(b>=9)
				s+=31;
			if(b>=10)
				s+=30;
			if(b>=11)
				s+=31;
			if(b>=12)
				s+=30;
			System.out.println(s);
		}
		
	}
}

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧