134k views
0 votes
JAVA In this exercise, you are given a phrase that starts with ‘A'. If the word after ‘A' begins with a vowel, add an ‘n' after the ‘A', otherwise, return the phrase as is. Example: grammer("A word") --> "A word" grammer("A excellent word") --> "An excellent word" public String grammar(String phrase) { }

User Bluelights
by
3.2k points

1 Answer

4 votes

Answer:

import java.util.*;

public class Main

{

public static void main(String[] args) {

System.out.println(grammar("A excellent word"));

}

public static String grammar(String phrase) phrase.charAt(2) == 'o'

}

Step-by-step explanation:

Create a function called grammar that takes one string parameter, phrase

Check if the character after "A", is one of the vowels, using charAt function. If it is, then insert "n" after "A". (To insert "n", concatenate two parts: "An", and the substring of the initial string after A).

Otherwise, return the initial string

User Eronisko
by
3.8k points