Not sure how to get a number instead of a letter for the output without using indexOf()

Viewed 33

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 substring method 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 use indexOf() ) and hardcode them in the println statements 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
0 Answers
Related