sab568
asked on
Get the month to display correctly on this script
Hi, Im trying to display the date correctly in this format: Tuesday, September 26 2004
using this script:
public class ProgramFive {
public static void main(String[] args) {
int a;
int y;
int m;
int d;
int month;
int day;
int year;
String output_s;
String s = "Sunday Monday Tuesday WednesdayThursday Friday Saturday ";
String NameOfTheDayOfTheWeek;
String g = "January February March April May June July August SeptemberOctober November December ";
String NameOfTheMonth;
System.out.println("Sebast ian Velasquez");
System.out.println("Please enter a month as an integer, eg: 1 means January, 2 means February.......,12 means december");
month = ConsoleIn.readLineInt();
System.out.println("Please enter a day of the month as an integer, eg: 1......31");
day = ConsoleIn.readLineInt();
System.out.println("Enter integer year, as 4 digits");
year = ConsoleIn.readLineInt();
a = (14 - month) / 12;
y = year - a;
m = month + 12 * a;
d = (day + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12) % 7;
NameOfTheDayOfTheWeek = s.substring(9 * d, 9 * d + 9);
NameOfTheMonth = g.substring(9 * m, 9 * m + 9);
System.out.println(NameOfT heDayOfThe Week + ", " + NameOfTheMonth + " " + day + " " + year );
}
}
I know the problem is on the NameOfTheMonth substring, im just not sure on how to write it correctly, any help would be greately appreciated
using this script:
public class ProgramFive {
public static void main(String[] args) {
int a;
int y;
int m;
int d;
int month;
int day;
int year;
String output_s;
String s = "Sunday Monday Tuesday WednesdayThursday Friday Saturday ";
String NameOfTheDayOfTheWeek;
String g = "January February March April May June July August SeptemberOctober November December ";
String NameOfTheMonth;
System.out.println("Sebast
System.out.println("Please
month = ConsoleIn.readLineInt();
System.out.println("Please
day = ConsoleIn.readLineInt();
System.out.println("Enter integer year, as 4 digits");
year = ConsoleIn.readLineInt();
a = (14 - month) / 12;
y = year - a;
m = month + 12 * a;
d = (day + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12) % 7;
NameOfTheDayOfTheWeek = s.substring(9 * d, 9 * d + 9);
NameOfTheMonth = g.substring(9 * m, 9 * m + 9);
System.out.println(NameOfT
}
}
I know the problem is on the NameOfTheMonth substring, im just not sure on how to write it correctly, any help would be greately appreciated
it'd be easier to store the names in an array.
> m = month + 12 * a;
try:
m = (month-1) * 9;
try:
m = (month-1) * 9;
ASKER
yes! that worked, now... the other problem i have with this script is that the spacing is weird. this is what the output is....
Thursday , January 1 2004
notice the weird spacing, what do you guys recomend changing while still keeping the same idea for the scirpt.
Thursday , January 1 2004
notice the weird spacing, what do you guys recomend changing while still keeping the same idea for the scirpt.
use String's trim() method to remove trailing spaces
ASKER
where should i put the trim at? after the system.out.println or where?
NameOfTheDayOfTheWeek = s.substring(9 * d, 9 * d + 9).trim();
NameOfTheMonth = g.substring(9 * m, 9 * m + 9).trim();
NameOfTheMonth = g.substring(9 * m, 9 * m + 9).trim();
ASKER
Perfect man, so how do I award you the points? do i just hit accept?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
awesome!, thanks for the help. I have a couple more of these to do an be sure im going to have trouble with em :) please keep an eye out for my questions as you have been GREAT help
thank you,
sab568
thank you,
sab568