-1

Hello here is the question.

  1. Check whether s1 has the prefix AAA and assign the result to a boolean variable b

  2. Check whether s1 has the prefix AAA and assign the result to a boolean variable b

This is what I have so far

/**
 *
 * @author samue_000
 */
public class N95e {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String s1 = "Welcome";
        String s2 = "welcome";
        boolean b = true;
        s1.lastIndexOf("AAA");



        if (s1.lastIndexOf("AAA") == true) {

        }
        System.out.println(s1.lastIndexOf("AAA"));

    }

}

Really stuck on this and mind has gone blank. So help would be appreciated

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Sam777
  • 19
  • 1
  • 2
  • 7

3 Answers3

0
boolean isStartAAA = s1.startsWith("AAA");
boolean isEndAAA = s1.endsWith("AAA");

Then print both values, you can achieve this with indexOf() as well but it unnecessary usage of the same.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Rahul Prasad
  • 747
  • 1
  • 9
  • 13
0

Oh I got it now

just do boolean b = s1.startsWith("AAA);

then print

Andy
  • 49,085
  • 60
  • 166
  • 233
Sam777
  • 19
  • 1
  • 2
  • 7
0

Or even more compact:

System.out.println(s1.startsWith("AAA")||s1.endsWith("AAA"));
Koen
  • 278
  • 1
  • 7