Computer Science, asked by deeksha39, 1 year ago

how many integer constants are allowed in Java? how are they written

Answers

Answered by jaswithabode
2
I am writing a program that counts the number of vowels and consonants from a sentence entered by the user. My code below counts the number of vowels but it give me strange numbers for consonant counts. For example if i enter "g" I get consonant count being 10.

import java.util.Scanner; public class VowelCount{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); System.out.print("Enter a sentence :"); String sentence = scan.nextLine(); String vowels = "aeiouAEIOU"; int vowelCount = 0; int consCount = 0; int i; for(i = 0; i < sentence.length(); i += 1){ char currentChar = sentence.charAt(i); int index; for(index = 0; index < vowels.length(); index += 1){ if(vowels.charAt(index) == (currentChar)){ vowelCount++; }else if(Character.isLetter(currentChar) && (vowels.charAt(index) == (currentChar))){ consCount++; } } } System.out.println(consCount); System.out.println(vowelCount); } }

hope you will mark my answer as brainlist answer

deeksha39: give relative answer do not give this
jaswithabode: it is wrong???
Similar questions