Please remember that homework must be handed in on time. No late homework will be accepted.
Review the readings from chapters 2 and 3 of your textbook and answer the following questions based on your textbook and the course lecture material.
c2 = a2 + b2
Will the output be an int or a double? Explain.
System.out.println(String.length(s));
Consider the following Java code fragment:
Scanner scan = new Scanner(System.in); System.out.print("Input your birthdate day: "); int day = scan.nextInt(); System.out.print("Input your birthdate month: "); String month = scan.nextLine(); System.out.println("Happy birthday on " + month + " " + day);
When this code is executed, the user never gets a chance to enter the birthdate month as shown below (user input is in italics). Why? Correct the code so the user can enter the day as an int and then the month as a String in that order successfully.
Input your birthdate day: 24 Input your birthdate month: Happy birthday on 24
HINT: Try the Java code on the computer and when prompted for the day,
enter
24 Purple Monkey Dishwasher
and watch what happens.
import java.util.*;
NAME WEBSITE PASSWORD homer simpson hsimpson apu nahasapeemapetilon anahasap montgomery burns mburns$$ lionel hutz lhutz$$$
Write a simple Java program with one class named PasswordGenerator. It should have a main method that prompts for the user's first name and the user's last name, and prints out the user's password in lowercase letters. You may assume that the user's input will be entirely lowercase letters and each name has no spaces or other punctuation. You may also assume that each input name has at least one letter. A sample run of the program might be (user input is in italics):
What is your first name? homer What is your last name? simpson YOUR WEBSITE PASSWORD IS: hsimpson
HINT: Concatenate 6 dollar signs on to the last name before you display the first 7 characters of the last name.
NOTE: You do not have to write this program in Eclipse, although you may do so, of course. Keep in mind that you will be required to write Java code on your written exams when you won't have the compiler to correct your errors. So you should try to learn to write some code by hand and work through the process on paper. Most professional programmers spend a good deal of time planning out their program code on paper before they go to the keyboard to type it in and test it.