Programming and Problem Solving with Java

(やまだぃちぅ) #1
709

first = in.readLine(); // Get first name
System.out.print("Enter last name: "); // Prompt for last name
last = in.readLine(); // Get last name
System.out.print("Enter middle initial: "); // Prompt for middle initial
middle = in.readLine(); // Get middle initial
firstLast = first + " "+ last; // Generate first format
System.out.println("Name in first-last format is "+ firstLast);
lastFirst = last + ", "+ first + ", "; // Generate second format
System.out.println("Name in last-first-initial format is "+
lastFirst + middle + ".");
firstInitialLast = first + " "+ middle +". " + last;
System.out.println("Name in first-initial-last format is "+
firstInitialLast):
}
}

8.public classDate
{
String month; // Month in string form
String year; // Year in string form
String day; // Day in string form

publicDate(String newMonth, String newYear, String newDay)
{ // Constructor
month = newMonth;
year = newYear;
day = newDay;
}

publicString monthDayYear() // Returns mm/dd/yyyy format
{
returnmonth + "/"+ day + "/"+ year;
}

publicString yearMonthDay() // Returns yyy-mm-dd format
{
returnyear + "-"+ month + "-"+ day;
}
} // End of Date class

Chapter 3 Exam Preparation Exercises



  1. a. 27
    b. 13
    c. 5

Free download pdf