1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class StringOops {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Type your name: ");
String name = console.nextString();
process(name);
}
public static void process(string "name") {
if (name == Whitaker) {
System.out.println("You must be really awesome.");
}
replace("a", "e");
toUppercase(name);
name.substring(0, 3);
System.out.println(name + " has " + name.length + " letters");
}
}
|
nextString should be nextstring should be Stringname should not be in quotesWhitaker should be in quotes==; must
use .equalsreplace without specifying a string
object (name)toUppercase should be
toUpperCasename. should come
before toUpperCase, not passed as a parameter to itname = to store the result
of toUpperCasename = to store the result
of substring() when
calling length
public class StringOops {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Type your name: ");
String name = console.next();
process(name);
}
public static void process(String "name") {
if (name.equals("Whitaker")) {
System.out.println("You must be really awesome.");
}
name = name.replace("a", "e");
name = name.toUpperCase();
name = name.substring(0, 3);
System.out.println(name + " has " + name.length() + " letters");
}
}