Sei sulla pagina 1di 1

Lab Assignment # 3

1 2 3 Write and run a Java program that inputs a persons name in the form First Middle Last and then prints it in the form Last, First M., where M. is the persons middle initial. (E.g. William Jefferson Clinton Would produce the output:- Clinton, William J. ) Write and run a program that initializes a String object with your first name and then prints it three times on the same line, separated by spaces, like this: Ram Ram Ram Write and run a Java program that prompts the user for his or her last name and first name separately and then prints a greeting like this: Enter your last name: JAIN Enter your first name: VINOD Hello, VINOD JAIN Write a program which does following on a given String. Count the number of occurrence of a particular character. (e.g. assassinations here s had come 5 times) Write a program that counts number of vowels and consonants in a given string. ( e.g. THIS IS MY BOOK) the output should be vowels:- 04 and consonants:-08 Write a program that takes a string (e.g. apple is a fruit). Obtain a substring from this string but starting from a second occurrence of a particular character (suppose. a) then output should be (a fruit) WAP to check weather a given string is a substring of other string. (e.g. drinking and other string is packages drinking water so here first string a substring of second hence the result must be TRUE) Write and run a Java program that enters a 10-digit string as a typical U.S. telephone number, extracts the 3-digit area code, the 3-digit exchange, and the remaining 4-digit number as separate strings, print them, and then prints the complete telephone number in the usual Formatting. A sample run might look like this: Enter 10-digit telephone number: 1234567890 You entered 1234567890 The area code is 123 The exchange is 456 The number is 7890 The complete telephone number is (123)456-7890 The Y2K problem was that many thousands of old software system around the world had been using only two digits for the year in stored dates. It was feared that on January 1, 2000, those dates were likely to be misinterpreted by the software as being january1, 1900, thus causing unpredictable errors and system crashes. Write a Java program that inputs a date in the form mm/dd/yy and outputs in the expanded form mm/dd/20yy. For example, the input 06/30/05 would be printed as 06/30/2005. Write and run a Java program that inputs the name of a month and then processes it by: echoing the input; extracting the first three letters; capitalizing them; printing that abbreviation; extracting each of the three letters as a separate char variable; using nested if and ifelse statements to identify the number of the month from the char variables; print the number of the month Here is a sample run: Enter the month: February You entered February Its abbreviation is FEB This is month number 2

4 5 6 7 8

10

Potrebbero piacerti anche