We were told to write this program which takes the date and tells you which day of the week it is:
Then change it so it only had one input, easy enough but no when the input is in mm/dd/yyyy format, you need to remove the slashes to get it to work, I thought I could but The prog doesnt work properly, anyway this is what ive tried:
Is there some easy way of doing this, am I on the right track ?!
I've modified the prog to print what the strings contain and it showed '02262004' .. which should work .. aahhh!
help!
*edit this soulda been a reply close plz!
Code:
import java.util.*;
import java.text.*;
import java.io.*;
class FindDayOfWeek {
public static void main( String[] args ) throws IOException {
String inputStr;
int year, month, day;
GregorianCalendar cal;
SimpleDateFormat sdf;
BufferedReader bufReader;
bufReader = new BufferedReader(
new InputStreamReader( System.in) );
System.out.print("Year (yyyy): ");
inputStr = bufReader.readLine();
year = Integer.parseInt(inputStr);
System.out.print("Month (1-12): ");
inputStr = bufReader.readLine();
month = Integer.parseInt(inputStr);
System.out.print("Day (1-31): ");
inputStr = bufReader.readLine();
day = Integer.parseInt(inputStr);
cal = new GregorianCalendar(year, month-1, day);
sdf = new SimpleDateFormat("EEEE");
System.out.print("");
System.out.print("Day of Week: " + sdf.format(cal.getTime()));
}
}
Code:
import java.util.*;
import java.text.*;
import java.io.*;
class FindDayOfWeekOneInput {
public static void main( String[] args ) throws IOException {
String inputStr;
int month, day, year;
GregorianCalendar cal;
SimpleDateFormat sdf;
BufferedReader bufReader;
bufReader = new BufferedReader(
new InputStreamReader( System.in));
String monthStr;
String dayStr;
String yearStr;
System.out.print("Enter the Date mm/dd/yyyy: ");
inputStr = bufReader.readLine();
monthStr = inputStr.substring(0,2);
dayStr = inputStr.substring(3,5);
yearStr = inputStr.substring(6,10);
month = Integer.parseInt(monthStr);
day = Integer.parseInt(dayStr);
year = Integer.parseInt(yearStr);
cal = new GregorianCalendar(month, day, year);
sdf = new SimpleDateFormat("EEEE");
System.out.print("");
System.out.print("Day of Week: " + sdf.format(cal.getTime()));
}
}
I've modified the prog to print what the strings contain and it showed '02262004' .. which should work .. aahhh!
help!
*edit this soulda been a reply close plz!