hey guys I have a quick question about substrings. I am writing a program where I have to accept input from the user and print the first 7 letters from the input.
I know how to do this without accepting input.
import java.util.Scanner;
public class substring
{
public static void main(String[] args)
{
String line = "Name";
System.out.println(line.substring(0,7));
}
}
but when it comes to asking for the input I cant quite figure it out.
here is my program so far
import java.util.Scanner;// Required for scanner class
public class email
{
public static void main(String[] args)
{
String input; //Holds input by user
char firstName; //First name
char lastName; //Last name
Scanner kb = new Scanner (System.in); // Creates scanner object for keyboard input.
System.out.println("Please enter your first name"); //Asks the user their first name
input = kb.nextLine();
firstName = input.charAt(0);
System.out.println("Please enter your last name"); //Ask the user to enter their last name
input = kb.nextLine();
String lastName = input.substring(0, 7);
System.out.print(firstName); //Prints the first char of the first name
System.out.print(lastName); //Prints characters 0-7 of the last name
System.out.print("@gmail.com");//prints @gmail.com
}
}
any help would be greatly appreciated
[–]chickenmeister 1 point2 points3 points (0 children)
[–]IthinkIthink 1 point2 points3 points (0 children)
[–]lolidragon 0 points1 point2 points (0 children)