Changing index number of a string
Hi,
My assignment is to write a program that takes as input a string and an integer n and displays the nth character of the string, but the twist is i have to get rid of the 0th index and make the string start at 1 instead of 0. I have it written so that it displays the character, but I can not figure out how to increase the index by 1. This is my first week learning this, so if my code looks ineffecient, im sorry but thats all i've learned so far. Thanks in advance.
import java.util.*;
publicclass ExtractChar{
publicstaticvoid main(String[] args){
Scanner keyboard =new Scanner(System.in);
System.out.println("Enter a word of your choosing:");
String input1 = keyboard.next();
System.out.println("Enter number of the character you would like displayed:");
int input2 = keyboard.nextInt();
String answer = input1.substring(+input2);
System.out.println("The character you are looking for is: " +answer);
}
}
Message was edited by:
rudsky

