Compare a letter in a String array in java?

Asked

Viewed 37 times

0

I’m doing an exercise in Java, on String, basically I have to enter a sentence with a maximum of 50 words separated by single space, after this check if all words start with the same letter, and the letter can be uppercase or lowercase.

I was able to transform the string that receives the sentence and an array, but I can’t find a way to verify that the words of each vector position have the same letter.
Then I just need a help, a light or a light to solve this part.

Follow the code of what I’ve been able to do so far.

import java.util.Scanner;

public class Uri1140 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String frase = sc.nextLine();

        while (frase != "*") {
            String sentenca = frase;
            String[] vetor = sentenca.split(" ");
            frase = sc.nextLine();
        }
        sc.close();
    }
}
  • 1

    Hello Jacqueline Welcome to the OS, edit your question and include the code you have already managed to do without it is difficult to help

  • I’m sorry to close your question, but this is more of a use case == instead of equals.

  • Just iterate through the array, taking the first letter of each string: https://ideone.com/e4NHWL - another detail is that vc should not close the System.in

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.