NameTester: import java.util.Scanner; public class NameTester { public static vo
ID: 3705171 • Letter: N
Question
NameTester:
import java.util.Scanner;
public class NameTester
{
public static void main(String[] args)
{
//create a Scanner object.
Scanner in=new Scanner(System.in);
System.out.println("Please enter your first name");
String first = in.next();
String blank = " ";
System.out.println("Please enter your last name");
String last = in.next();
String full = first + blank + last;
System.out.println(full.substring(0,1));
System.out.println(full.substring(1,2));
System.out.println(full.substring(2,3));
System.out.println(full.substring(3,4));
System.out.println(full.substring(4,5));
System.out.println(full.substring(5,6));
System.out.println(full.substring(6,7));
System.out.println(full.substring(7,8));
System.out.println(full.substring(8,9));
System.out.println(full.substring(9,10));
}
}?
must be in java:
Problem 5: This one you will also do on your own and it will be an adaptation of a problem from Lab 4.
Copy you class named NameTester form Lab4. (You will not need a class. This will have the main method in it).
Keep - Import Scanner
Keep - Create a Scanner object
Keep - Prompt for your first name.
Keep - Create a variable for your first and get the user input for your first name.
Keep - Prompt for your last name.
Keep - Create a variable for your last name and get the input for your last name.
Keep - Create a variable for a blank.
Keep - Create a variable for your full name and assign it your first and last name and a blank using the + operator.
Using the variable for your full name, use the substring method (use the table on page 159) as a guide) print out your name with one letter on each line. This should be accomplished using a loop. Remember you can get the length of the string from the method .length(). If you do not use a loop, you will not get credit.
M
S
.
W
Explanation / Answer
NameTester.java
import java.util.Scanner;
public class NameTester {
public static void main(String[] args)
{
//create a Scanner object.
Scanner in=new Scanner(System.in);
System.out.println("Please enter your first name");
String first = in.next();
String blank = " ";
System.out.println("Please enter your last name");
String last = in.next();
String full = first + blank + last;
for(int i=0;i<full.length();i++) {
System.out.println(full.substring(i,i+1));
}
}
}
Output:
Please enter your first name
Suresh
Please enter your last name
Murapaka
S
u
r
e
s
h
M
u
r
a
p
a
k
a
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.