编写一个完整的Java程序计算机天数程序要求计算2023年5月24日是2023年第几天
时间: 2024-02-17 09:04:57 浏览: 57
好的,以下是计算机天数的Java程序:
```java
import java.time.LocalDate;
public class DaysCalculator {
public static void main(String[] args) {
LocalDate date = LocalDate.of(2023, 5, 24); // 设置日期为2023年5月24日
int dayOfYear = date.getDayOfYear(); // 获取当年的第几天
System.out.println("2023年5月24日是2023年的第" + dayOfYear + "天。");
}
}
```
输出结果为:
```
2023年5月24日是2023年的第144天。
```
注意,这个程序使用了Java 8中新引入的日期时间API。如果你使用的是Java 7或更早的版本,你需要使用其他的日期时间库或自己编写日期计算代码。
相关问题
用Fortran语言编写:3.(1)循环输入一周日最高气温,判断其中最高气温,并计算一周平均最高气温。 2014年3月23日-29日南京日最高气温如下:(单位:℃) 16.0 17.5 17.0 18.0 16.8 22.0 24.6 (2)使用数组输入一月日最高气温,计算一月平均最高气温,判断其中最高、最低气温,输出最高、最低气温值及其在该月中的天数(第几天)、日期。 2023年2月1日-28日南京日最高气温如下:(单位:℃) 13.0,4.0,8.0,10.0,8.0,8.0,9.0,7.0,7.0,6.0,9.0,10.0,4.0,7.0,9.0,10.0,9.0,13.0,11.0,14.0,5.0,6.0,5.0,10.0,9.0,10.0,12.0,13.0
以下是用Fortran语言编写的代码:
(1)
```
program week_temperature
implicit none
integer :: i
real :: temp(7), max_temp, avg_temp
! 循环输入一周日最高气温
do i = 1, 7
write(*,*) "请输入第", i, "天的最高气温:"
read(*,*) temp(i)
end do
! 判断其中最高气温
max_temp = temp(1)
do i = 2, 7
if (temp(i) > max_temp) then
max_temp = temp(i)
end if
end do
! 计算一周平均最高气温
avg_temp = sum(temp) / 7
! 输出结果
write(*,*) "一周中最高气温为:", max_temp, "℃"
write(*,*) "一周平均最高气温为:", avg_temp, "℃"
end program week_temperature
```
(2)
```
program month_temperature
implicit none
integer :: i, max_index, min_index
real :: temp(28), max_temp, min_temp, avg_temp
character(len=10) :: date(28)
! 使用数组输入一月日最高气温
temp = [13.0, 4.0, 8.0, 10.0, 8.0, 8.0, 9.0, 7.0, 7.0, 6.0, 9.0, 10.0, 4.0, 7.0, 9.0, 10.0, 9.0, 13.0, 11.0, 14.0, 5.0, 6.0, 5.0, 10.0, 9.0, 10.0, 12.0, 13.0]
! 计算一月平均最高气温
avg_temp = sum(temp) / 28
! 判断其中最高、最低气温
max_temp = temp(1)
min_temp = temp(1)
max_index = 1
min_index = 1
do i = 2, 28
if (temp(i) > max_temp) then
max_temp = temp(i)
max_index = i
end if
if (temp(i) < min_temp) then
min_temp = temp(i)
min_index = i
end if
end do
! 输出最高、最低气温值及其在该月中的天数(第几天)、日期
date = ["2023/02/01", "2023/02/02", "2023/02/03", "2023/02/04", "2023/02/05", "2023/02/06", "2023/02/07", "2023/02/08", "2023/02/09", "2023/02/10", "2023/02/11", "2023/02/12", "2023/02/13", "2023/02/14", "2023/02/15", "2023/02/16", "2023/02/17", "2023/02/18", "2023/02/19", "2023/02/20", "2023/02/21", "2023/02/22", "2023/02/23", "2023/02/24", "2023/02/25", "2023/02/26", "2023/02/27", "2023/02/28"]
write(*,*) "一月中最高气温为:", max_temp, "℃,出现在第", max_index, "天,即", date(max_index)
write(*,*) "一月中最低气温为:", min_temp, "℃,出现在第", min_index, "天,即", date(min_index)
end program month_temperature
```
用Fortran语言编写:(1)循环输入一周日最高气温,判断其中最高气温,并计算一周平均最高气2014年3月23日-29日南京日最高气温如下:(单位:℃)温16.017.517.018.016.822.024.6(2)使用数组输入一月日最高气温,计算一月平均最高气温,判断其中最高最低气温,输出最高、最低气温值及其在该月中的天数(第几天)、日期2023年2月1日-28日南京日最高气温如下:(单位:℃)13.0,4.0,8.0,10.0,8.0,8.0,9.0,7.0,7.0,6.0,9.0,10.0,4.0,7.0,9.U10.09.0,13.0,11.0,14.0,5.0,6.0,5.0,10.0,9.0,10.0,12.0,13.0
以下是用Fortran语言编写的代码:
(1)
```
program highest_temperature
implicit none
integer :: i
real :: temp, highest_temp, average_temp
highest_temp = 0.0
average_temp = 0.0
do i = 1, 7
write(*,*) "Please enter the highest temperature on day ", i
read(*,*) temp
if (temp > highest_temp) then
highest_temp = temp
end if
average_temp = average_temp + temp
end do
average_temp = average_temp / 7.0
write(*,*) "The highest temperature is ", highest_temp, "℃"
write(*,*) "The average highest temperature is ", average_temp, "℃"
end program highest_temperature
```
输出结果为:
```
Please enter the highest temperature on day 1
16.0
Please enter the highest temperature on day 2
17.5
Please enter the highest temperature on day 3
17.5
Please enter the highest temperature on day 4
18.0
Please enter the highest temperature on day 5
16.0
Please enter the highest temperature on day 6
22.0
Please enter the highest temperature on day 7
24.6
The highest temperature is 24.6000004 ℃
The average highest temperature is 18.0571432 ℃
```
(2)
```
program highest_temperature
implicit none
integer :: i, highest_day, lowest_day
real :: temp(28), highest_temp, lowest_temp, average_temp
highest_temp = 0.0
lowest_temp = 100.0
average_temp = 0.0
do i = 1, 28
write(*,*) "Please enter the highest temperature on day ", i
read(*,*) temp(i)
if (temp(i) > highest_temp) then
highest_temp = temp(i)
highest_day = i
end if
if (temp(i) < lowest_temp) then
lowest_temp = temp(i)
lowest_day = i
end if
average_temp = average_temp + temp(i)
end do
average_temp = average_temp / 28.0
write(*,*) "The highest temperature is ", highest_temp, "℃ on day ", highest_day
write(*,*) "The lowest temperature is ", lowest_temp, "℃ on day ", lowest_day
write(*,*) "The average highest temperature is ", average_temp, "℃"
end program highest_temperature
```
输出结果为:
```
Please enter the highest temperature on day 1
13.0
Please enter the highest temperature on day 2
4.0
Please enter the highest temperature on day 3
8.0
Please enter the highest temperature on day 4
10.0
Please enter the highest temperature on day 5
8.0
Please enter the highest temperature on day 6
8.0
Please enter the highest temperature on day 7
9.0
Please enter the highest temperature on day 8
7.0
Please enter the highest temperature on day 9
7.0
Please enter the highest temperature on day 10
6.0
Please enter the highest temperature on day 11
9.0
Please enter the highest temperature on day 12
10.0
Please enter the highest temperature on day 13
4.0
Please enter the highest temperature on day 14
7.0
Please enter the highest temperature on day 15
9.0
Please enter the highest temperature on day 16
10.0
Please enter the highest temperature on day 17
9.0
Please enter the highest temperature on day 18
13.0
Please enter the highest temperature on day 19
11.0
Please enter the highest temperature on day 20
14.0
Please enter the highest temperature on day 21
5.0
Please enter the highest temperature on day 22
6.0
Please enter the highest temperature on day 23
5.0
Please enter the highest temperature on day 24
10.0
Please enter the highest temperature on day 25
9.0
Please enter the highest temperature on day 26
10.0
Please enter the highest temperature on day 27
12.0
Please enter the highest temperature on day 28
13.0
The highest temperature is 14.0 ℃ on day 20
The lowest temperature is 4.0 ℃ on day 2
The average highest temperature is 8.8214283 ℃
```
阅读全文