谁能帮我修改一下,让这个程序能运行
importjava.util.Scanner;publicclassmyBirthday{publicstaticvoidmain(String[]args){intd...
import java.util.Scanner;
public class myBirthday
{
public static void main(String[] args)
{
int date, month, year;
String name;
Scanner scan = new Scanner (System.in);
System.out.println ("Your name: ");
name = scan.nextLine();
// Ask for the user's name
System.out.println ("Day:");
date = scan.nextInt();
// Ask for the user's birth date
System.out.println ("Month:");
month = scan.nextInt();
// Ask for the user's month of birth
System.out.println ("Year:");
year = scan.nextInt();
// Ask for user's year of birth
System.out.println ("Your name is:" +name);
System.out.println ("The length of your name is "+name.length());
// Print out the name results
System.out.println("Your birthday is " + year + month + date);
myBirthday user = new myBirthday(name, date, month, year);
System.out.println("Your birthday is " + user.oddoreven(Date) );
System.out.println("The month name of your birth is: " + user.monthName(Month) );
System.out.println("The year of your birthday is:" +user.leapornot(Year) );
}
// Print out the birth date results
// ----------------------------------------------------------------------
// Method to determines length of name
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Method to determine if date is odd or even
// ----------------------------------------------------------------------
public String oddoreven (int date)
{
String Date;
if (date%2==0)
Date = "even";
else
Date = "odd";
return Date;
}
// ----------------------------------------------------------------------
// Method to return the name of the month
// ----------------------------------------------------------------------
public String monthName(int month)
{
String Month;
switch (month)
{
case 1:
Month = "January";break;
case 2:
Month = "Febtruary";break;
case 3:
Month = "March";break;
case 4:
Month = "April";break;
case 5:
Month = "May";break;
case 6:
Month = "June";break;
case 7:
Month = "July";break;
case 8:
Month = "Augyst";break;
case 9:
Month = "September";break;
case 10:
Month = "October";break;
case 11:
Month = "November";break;
case 12:
Month = "December";break;
default:
System.out.println ("error");
}
return Month;
}
public String leapornot (int year)
{
String Year;
if((year%4==0 && year%100!=0) || year%100==0)
Year = " a leap year ";
else
Year = " not a leap year ";
return Year;
}
} 展开
public class myBirthday
{
public static void main(String[] args)
{
int date, month, year;
String name;
Scanner scan = new Scanner (System.in);
System.out.println ("Your name: ");
name = scan.nextLine();
// Ask for the user's name
System.out.println ("Day:");
date = scan.nextInt();
// Ask for the user's birth date
System.out.println ("Month:");
month = scan.nextInt();
// Ask for the user's month of birth
System.out.println ("Year:");
year = scan.nextInt();
// Ask for user's year of birth
System.out.println ("Your name is:" +name);
System.out.println ("The length of your name is "+name.length());
// Print out the name results
System.out.println("Your birthday is " + year + month + date);
myBirthday user = new myBirthday(name, date, month, year);
System.out.println("Your birthday is " + user.oddoreven(Date) );
System.out.println("The month name of your birth is: " + user.monthName(Month) );
System.out.println("The year of your birthday is:" +user.leapornot(Year) );
}
// Print out the birth date results
// ----------------------------------------------------------------------
// Method to determines length of name
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Method to determine if date is odd or even
// ----------------------------------------------------------------------
public String oddoreven (int date)
{
String Date;
if (date%2==0)
Date = "even";
else
Date = "odd";
return Date;
}
// ----------------------------------------------------------------------
// Method to return the name of the month
// ----------------------------------------------------------------------
public String monthName(int month)
{
String Month;
switch (month)
{
case 1:
Month = "January";break;
case 2:
Month = "Febtruary";break;
case 3:
Month = "March";break;
case 4:
Month = "April";break;
case 5:
Month = "May";break;
case 6:
Month = "June";break;
case 7:
Month = "July";break;
case 8:
Month = "Augyst";break;
case 9:
Month = "September";break;
case 10:
Month = "October";break;
case 11:
Month = "November";break;
case 12:
Month = "December";break;
default:
System.out.println ("error");
}
return Month;
}
public String leapornot (int year)
{
String Year;
if((year%4==0 && year%100!=0) || year%100==0)
Year = " a leap year ";
else
Year = " not a leap year ";
return Year;
}
} 展开
1个回答
展开全部
public class myBirthday {
private int Date, Month, Year;
private String name;
public myBirthday(String name, int Date, int Month, int Year) {
this.name = name;
this.Date = Date;
this.Month = Month;
this.Year = Year;
}
public static void main(String[] args) {
int Date, Month, Year;
String name;
Scanner scan = new Scanner(System.in);
System.out.println("Your name: ");
name = scan.nextLine();
// Ask for the user's name
System.out.println("Day:");
Date = scan.nextInt();
// Ask for the user's birth date
System.out.println("Month:");
Month = scan.nextInt();
// Ask for the user's month of birth
System.out.println("Year:");
Year = scan.nextInt();
// Ask for user's year of birth
System.out.println("Your name is:" + name);
System.out.println("The length of your name is " + name.length());
// Print out the name results
System.out.println("Your birthday is " + Year + Month + Date);
myBirthday user = new myBirthday(name, Date, Month, Year);
System.out.println("Your birthday is " + user.oddoreven(Date));
System.out.println("The month name of your birth is: "
+ user.monthName(Month));
System.out.println("The year of your birthday is:"
+ user.leapornot(Year));
}
// Print out the birth date results
// ----------------------------------------------------------------------
// Method to determines length of name
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Method to determine if date is odd or even
// ----------------------------------------------------------------------
public String oddoreven(int date) {
String Date;
if (date % 2 == 0)
Date = "even";
else
Date = "odd";
return Date;
}
// ----------------------------------------------------------------------
// Method to return the name of the month
// ----------------------------------------------------------------------
public String monthName(int month) {
String Month = null;
switch (month) {
case 1:
Month = "January";
break;
case 2:
Month = "Febtruary";
break;
case 3:
Month = "March";
break;
case 4:
Month = "April";
break;
case 5:
Month = "May";
break;
case 6:
Month = "June";
break;
case 7:
Month = "July";
break;
case 8:
Month = "Augyst";
break;
case 9:
Month = "September";
break;
case 10:
Month = "October";
break;
case 11:
Month = "November";
break;
case 12:
Month = "December";
break;
default:
System.out.println("error");
}
return Month;
}
public String leapornot(int year) {
String Year;
if ((year % 4 == 0 && year % 100 != 0) || year % 100 == 0)
Year = " a leap year ";
else
Year = " not a leap year ";
return Year;
}
}
private int Date, Month, Year;
private String name;
public myBirthday(String name, int Date, int Month, int Year) {
this.name = name;
this.Date = Date;
this.Month = Month;
this.Year = Year;
}
public static void main(String[] args) {
int Date, Month, Year;
String name;
Scanner scan = new Scanner(System.in);
System.out.println("Your name: ");
name = scan.nextLine();
// Ask for the user's name
System.out.println("Day:");
Date = scan.nextInt();
// Ask for the user's birth date
System.out.println("Month:");
Month = scan.nextInt();
// Ask for the user's month of birth
System.out.println("Year:");
Year = scan.nextInt();
// Ask for user's year of birth
System.out.println("Your name is:" + name);
System.out.println("The length of your name is " + name.length());
// Print out the name results
System.out.println("Your birthday is " + Year + Month + Date);
myBirthday user = new myBirthday(name, Date, Month, Year);
System.out.println("Your birthday is " + user.oddoreven(Date));
System.out.println("The month name of your birth is: "
+ user.monthName(Month));
System.out.println("The year of your birthday is:"
+ user.leapornot(Year));
}
// Print out the birth date results
// ----------------------------------------------------------------------
// Method to determines length of name
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Method to determine if date is odd or even
// ----------------------------------------------------------------------
public String oddoreven(int date) {
String Date;
if (date % 2 == 0)
Date = "even";
else
Date = "odd";
return Date;
}
// ----------------------------------------------------------------------
// Method to return the name of the month
// ----------------------------------------------------------------------
public String monthName(int month) {
String Month = null;
switch (month) {
case 1:
Month = "January";
break;
case 2:
Month = "Febtruary";
break;
case 3:
Month = "March";
break;
case 4:
Month = "April";
break;
case 5:
Month = "May";
break;
case 6:
Month = "June";
break;
case 7:
Month = "July";
break;
case 8:
Month = "Augyst";
break;
case 9:
Month = "September";
break;
case 10:
Month = "October";
break;
case 11:
Month = "November";
break;
case 12:
Month = "December";
break;
default:
System.out.println("error");
}
return Month;
}
public String leapornot(int year) {
String Year;
if ((year % 4 == 0 && year % 100 != 0) || year % 100 == 0)
Year = " a leap year ";
else
Year = " not a leap year ";
return Year;
}
}
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询