Prompt:
Write a program that declares a string variable, assigns it "I'm still confused! do I like programming or I don't?", and then uses the
substringmethod to extract and output the substrings shown below from that string. You should also manually find the right index/position number for each '?' ( don't useindexOf()) and hardcode them in theprintlnstatements in your program so that it displays numbers instead of the "?" characters.
My code is as follows:
public class substring{
public static void main(String[] args){
String confused = new String("still confused! do I like programming or I don't?");
// first line
System.out.println("Substring starting from index? " + confused);
//second line
System.out.print("Substring starting from index? and ending at? : ");
String c = confused.substring(6,14);
System.out.println(c);
//third line with length
System.out.print("The length of the substring from index ? and ending at ? is: ");
System.out.println(c.substring(c.length() - 1));
}
}
I keep getting a "d" instead of an "8" and I cannot use indexOf() to get the "8". The output for the last line should look like:
The length of the substring from index ? and ending at ? is: 8