Hi,
this is the question:
Your program must accept a String (str) & an Integer(pos), returns true if the character at a given position (pos) is a vowel or false otherwise
Here is my attempt:
import java.util.*; public class VowelPositionFromString { //accepts a String (str) & an Integer(pos), returns true if the character at a given position (pos) is a vowel or false otherwise public static void main (String[]args){ Scanner in = new Scanner (System.in); String str; int pos, letter,letterPosition=0; System.out.printf("Enter a string\n"); str = in.nextLine(); System.out.printf("Enter an intreger position\n"); pos = in.nextInt(); for (int i=0; i<str.length(); i++) { letter= str.charAt(i); if (Character.isUpperCase(letter)) { letterPosition =letter - 'A' +1; if(letterPosition == pos) { System.out.printf("True"); } } else if (Character.isLowerCase(letter)) { letterPosition =letter - 'a' +1; if(letterPosition == pos) { System.out.printf("True"); } } } } }
The issue is that I don't know how to link it to a vowel position.
I was thinking about declaring 2 contants:
1. vowelPositions for uppercase letters
2. vowelPositions for lowercase letters
Then I would know how to incorporate it in the program.
I hope I explained well, please assist.
So far my program returns true if a letter in the string corresponds with the position entered.