-2

this is my code....and problem I need to have an input from user where the first letter is used , then from the second user input from 0 to 5 the characters are used, and finally generate a random number....I have tried everything for the second portion (0 to 5 characters) and I've searched the internet for different answers but nothing works.

here is the source code :

//********************************************************************
//  NameNumberConverter.java       Java Foundations
//
//
//********************************************************************

import java.lang.*;
import java.util.Scanner;
import java.util.*;
public class NameNumberConverter
{
//-----------------------------------------------------------------
// First the user inputs their first and last names
//-----------------------------------------------------------------
public static void main(String[] args)
{

   Scanner sc = new Scanner( System.in );


 System.out.println ("Please insert your first name : ");
 String Firstname=sc.next();


 System.out.println ("Please insert your last name : ");
 String Lastname=sc.next();



  char end = Firstname.charAt(0);
  char end2 = Lastname.charAt(0, 5);


 System.out.println ("The converted result is: " + end + end2);


    sc.close();


  }
}

Thanks for anything that can be helpful. as I am a student and definitely not a pro....

Trevor Tracy
  • 356
  • 1
  • 10
cpdl4485
  • 3
  • 2

1 Answers1

0

Unfortunately charAt(int) only takes one integer parameter.

I think what you are looking for is the range of characters for the last name. You can do something like this to get characters within a specific range for a string.

// string variable for example
String exampleString = "J. Smith";
// here is how to get a range of characters with substring(int,int)
String lastName = exmapleString.substring(3,7);
// print out "Smith"
System.out.println(lastName);

Now remember that the index value of strings starts at [0]

dave
  • 575
  • 4
  • 19