Computer Science, asked by Anonymous, 5 months ago

JAVA Word Based Programming ..solve it plzz...

Computer Science with JAVA for class 11th - by Sumita Arora

Attachments:

Answers

Answered by Oreki
2

Answer :

public class AnalyseSentence {

// A method for counting Vowels.

static int[ ] getVowelsAndLength(String word) {

int vowels = 0, actualLength = 0;

final char[ ] VOWELS = {'a', 'e', 'i', 'o', 'u'};

for (char letter : word.toCharArray( ))

if (Character.isLetter(letter)) {

actualLength++;

for (char vowel : VOWELS)

if (letter = = vowel)

vowels++;

}

return new int[ ] {vowels, actualLength};

}

// A method for printing no. of Consonants and Vowels in a word.

static void analyzeWord(String word) {

// Getting vowels and consonants.

int[ ] wordInfo = getVowelsAndLength(word);

int vowels = wordInfo[0],

consonants = wordInfo[1] - wordInfo[0];

System.out.printf("Word - %s%n Vowels - %d%n Consonants - %d%n",

word, vowels, consonants);

}

public static void main(String[ ] args) {

System.out.print("Enter a sentence to be analysed - ");

// Converting accepted sentence to array using split( ).

String[ ] sentence = new java.util.Scanner(System.in).nextLine( ).split(" ");

// Analyse and print each word seperately.

for (String word : sentence)

analyzeWord(word);

}

}

Answered by Anonymous
25

{\huge{\star}} AnsweR

public class AnalyseSentence {

// A method for counting Vowels.

static int[ ] getVowelsAndLength(String word) {

int vowels = 0, actualLength = 0;

final char[ ] VOWELS = {'a', 'e', 'i', 'o', 'u'};

for (char letter : word.toCharArray( ))

if (Character.isLetter(letter)) {

actualLength++;

for (char vowel : VOWELS)

if (letter = = vowel)

vowels++;

}

return new int[ ] {vowels, actualLength};

}

// A method for printing no. of Consonants and Vowels in a word.

static void analyzeWord(String word) {

// Getting vowels and consonants.

int[ ] wordInfo = getVowelsAndLength(word);

int vowels = wordInfo[0],

consonants = wordInfo[1] - wordInfo[0];

System.out.printf("Word - %s%n Vowels - %d%n Consonants - %d%n",

word, vowels, consonants);

}

public static void main(String[ ] args) {

System.out.print("Enter a sentence to be analysed - ");

// Converting accepted sentence to array using split( ).

String[ ] sentence = new java.util.Scanner(System.in).nextLine( ).split(" ");

// Analyse and print each word seperately.

for (String word : sentence)

analyzeWord(word);

}

}

▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅

Sorry for copy paste ! (⌒_⌒;)

Similar questions