forked from erenuygur/EfficientHouseJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3.java
More file actions
31 lines (25 loc) · 1.27 KB
/
Q3.java
File metadata and controls
31 lines (25 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package homeworks.chapter2;
/*
Write a program that starts with the string variable first set to your first name
and the string variable last set to your last name. Both names should be all lowercase. Your program should then create a new string that contains your full name in
pig latin with the first letter capitalized for the first and last name. Use only the pig
latin rule of moving the first letter to the end of the word and adding “ay.” Output
the pig latin name to the screen. Use the substring and toUpperCase methods
to construct the new name.
For example, given
first = "walt";
last = "savitch";
the program should create a new string with the text “Altway Avitchsay” and print it.
*/
public class Q3 {
public static void main(String[] args) {
java.util.Scanner kb = new java.util.Scanner(System.in);
System.out.print("First name:");
String first =kb.nextLine();
System.out.print("Last name:");
String last = kb.nextLine();
String pigLatinFirst = first.substring(1, 2).toUpperCase() + first.substring(2) + first.substring(0, 1) + "ay";
String pigLatinLast = last.substring(1, 2).toUpperCase() + last.substring(2) + last.substring(0, 1) + "ay";
System.out.println(pigLatinFirst + " " + pigLatinLast);
}
}