gpt4 book ai didi

java - 我在我的代码中输入了一些针对控制台的内容,但我找不到我搞砸的地方

转载 作者:行者123 更新时间:2023-12-04 03:40:11 24 4
gpt4 key购买 nike

<分区>

我正在对我的作业进行测试以确保一切正常,我不小心在我的代码中输入了一个用于控制台的输入,结果输出不再正确。这是代码:

import java.util.*;

public class JTCalendar {
//This defines how big the calendar is
public static final int Width = 5;

public static void drawMonth(int month,int day) {

//Ascii art of a robot man
System.out.println(" /\\ /\\");
System.out.println(" / \\ / \\");
System.out.println(" ---------------");
System.out.println("(| (o) (o) |)");
System.out.println(" | wwww |");
System.out.println(" ----------------");

//This finds the center
for(int i = 1; i <= 1; i++) {
for(int j = 1; j <= (Width * 7) / 2; j++) {
System.out.print(" ");
}
System.out.print(month);
for(int d = 1; d <= (Width * 7) / 2 ; d++) {
System.out.print(" ");
}
System.out.println();

我相信错误是在这个区域的某个地方出现的,因为这是一个输出困惑的区域

      }
//Size calculator
for(int g =1; g <= Width * 7; g++) {
System.out.print("=");
}
System.out.println();
drawRow(5);
displayDate(month,day);
}
//Start of the rows
public static void drawRow(int row) {
int day = 1;
for(int i = 0; i < row; i++) {

System.out.print("|");
for(int a = 1; a <= 7; a++) {

int length=String.valueOf(day).length();
for(int j = 1; j < Width - length; j++) {
System.out.print(" ");
}

System.out.print(day);
day++;
System.out.print("|");
}
System.out.println();
for(int t = 1; t < (Width /2); t++) {
System.out.print("|");
for(int h = 1; h<=7; h++) {

for(int f = 1; f <= Width - 1; f++) {
System.out.print(" ");
}
System.out.print("|");
}
}
for(int e = 1; e <= Width * 7; e++) {
System.out.print("=");
}
System.out.println();
}
//End of the rows
}
//Below displays the date
public static void displayDate(int month, int day) {
System.out.println("Month: " + month + "\nDay: " + day);
}
//End display
//Below seperates month and day into two ints
public static int monthFromDate(String date) {
String tokens[] = date.split("/");
return Integer.parseInt(tokens[0]);
}

我相信低于此的任何内容都是正确的,但我仍将其包括在内

public static int dayFromDate(String date) {
String tokens[] = date.split("/");
return Integer.parseInt(tokens[1]);
}
//End seperation of month and day

public static void main(String[] args) {
//Main scanner console
Scanner console = new Scanner(System.in);
System.out.print("What date would you like to look at? (mm/dd): ");
String date = console.next();
int day = dayFromDate(date);
int month = monthFromDate(date);
drawMonth(month, day);
//This draws the ascii calendar

Calendar cal = Calendar.getInstance();
day = cal.get(Calendar.DATE);
month = cal.get(Calendar.MONTH) + 1;
System.out.println("\nToday is: " + month + "/" + day + "\n");
drawMonth(month,day);
//This draws the calandar for the current date
}
}

错误的输出:

    /\     /\
/ \ / \
---------------
(| (o) (o) |)
| wwww |
----------------
2
===================================
| 1| 2| 3| 4| 5| 6| 7|
| | | | | | | |===================================
| 8| 9| 10| 11| 12| 13| 14|
| | | | | | | |===================================
| 15| 16| 17| 18| 19| 20| 21|
| | | | | | | |===================================
| 22| 23| 24| 25| 26| 27| 28|
| | | | | | | |===================================
| 29| 30| 31| 32| 33| 34| 35|
| | | | | | | |===================================
Month: 2
Day: 25

Today is: 2/13

/\ /\
/ \ / \
---------------
(| (o) (o) |)
| wwww |
----------------
2
===================================
| 1| 2| 3| 4| 5| 6| 7|
| | | | | | | |===================================
| 8| 9| 10| 11| 12| 13| 14|
| | | | | | | |===================================
| 15| 16| 17| 18| 19| 20| 21|
| | | | | | | |===================================
| 22| 23| 24| 25| 26| 27| 28|
| | | | | | | |===================================
| 29| 30| 31| 32| 33| 34| 35|
| | | | | | | |===================================
Month: 2
Day: 13

良好的输出:

    /\     /\
/ \ / \
---------------
(| (o) (o) |)
| wwww |
----------------
2
===================================
| 1| 2| 3| 4| 5| 6| 7|
| | | | | | | |
===================================
| 8| 9| 10| 11| 12| 13| 14|
| | | | | | | |
===================================
| 15| 16| 17| 18| 19| 20| 21|
| | | | | | | |
===================================
| 22| 23| 24| 25| 26| 27| 28|
| | | | | | | |
===================================
| 29| 30| 31| 32| 33| 34| 35|
| | | | | | | |
===================================
Month: 2
Day: 25

Today is: 2/13

/\ /\
/ \ / \
---------------
(| (o) (o) |)
| wwww |
----------------
2
===================================
| 1| 2| 3| 4| 5| 6| 7|
| | | | | | | |
===================================
| 8| 9| 10| 11| 12| 13| 14|
| | | | | | | |
===================================
| 15| 16| 17| 18| 19| 20| 21|
| | | | | | | |
===================================
| 22| 23| 24| 25| 26| 27| 28|
| | | | | | | |
===================================
| 29| 30| 31| 32| 33| 34| 35|
| | | | | | | |
===================================
Month: 2
Day: 13

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com