Need help with Java code


#1

For this program supposed to enter a word and number then it will tell you the letter in the word at the number you entered

EXAMPLE:
hello
3
In word “hello”, the letter at index 3 is “l”

everything should be solid, but im super new so if you see something let me know, the teacher said its good so far i just dont know what to fill in the ???s with…



import java.util.Scanner;

public class LetterAt {
    public static void main(String[] args) {
	    Scanner in = new Scanner(System.in);
	    String word;
	    int index;
		
		System.out.println("Enter word: ");
	        word = in.next();
		System.out.println("Enter index: ");
		index = in.next(); 
		
	        if (index >= word.??? && index < word.???) {
		        System.out.printf("In word \"%s\", the letter " + " at index %d is '%c'.\n", word);
	        } 
		else {
	            System.out.printf("%d is not a legal index " + "for \"%s\".\n", index, word);	
            }
    }			
}



#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.