Question

JAVA Array 3. Write a method called noVowels that takes a String as input and returns...

JAVA Array

3. Write a method called noVowels that takes a String as input and returns true if it doesn't contain any vowels (a, e, i, o, u)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
class Main2
{
public static void main(String[] args)
{
   System.out.print("Enter a string : ");
       Scanner sc = new Scanner(System. in);
String line = sc. nextLine();               //reading string
            Boolean k;
            k=noVowels(line);                       //functoin call to noVowels function
            System.out.println(k);                   //printing the result either true or false;

}

public static Boolean noVowels(String line)
{
   int vowels = 0;                   //we are initalizing the vowels count to zero .
       line = line.toLowerCase();       //we are converting the upper case lettr to lowercase because it menstioned with vowels(a,e,i,o,u) only
       for(int i = 0; i < line.length(); ++i)       //running for loop upto the the string lenght
{
char ch = line.charAt(i);               //we are extracting the single charcter from the string
if(ch == 'a' || ch == 'e' || ch == 'i'   //we are comparing the each and every character with lower case lettters only we are using the logical OR operator
|| ch == 'o' || ch == 'u')
           {
++vowels;                           //if we found any vowel in the string we are incrementing count of vowel by one
}
  
}
      
       if(vowels==0)                   //checking if vowel count ==0 then it doesnot contain any vowels.
               return true;           //returning the true
           else
               return false;       //       if it contain atleast one vowel the it print as false.

}
}

OUTPUT:

case1:

C:\Users\rajesh\Desktop>javac Main2.java

C:\Users\rajesh\Desktop>java Main2
Enter a string : klgdfs
true

CASE2:

C:\Users\rajesh\Desktop>javac Main2.java

C:\Users\rajesh\Desktop>java Main2
Enter a string : ramu
false

Catherstrajesh Desktop Man2java - Notepad Edit Search View Encoding Language Settings Tools Macro Run Plugins Window ? Mart2jC:\Users\rajesh\Desktop>javac Main2.java C:\Users\rajesh\Desktop>java Main2 Enter a string : kigdfs true C:\Users\rajesh\Desk

Add a comment
Know the answer?
Add Answer to:
JAVA Array 3. Write a method called noVowels that takes a String as input and returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon...

    Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon that accepts an array of integers as its only parameter, and returns the int that occurs most frequently. Break ties by returning the lower value For example, {1,2,2,3,4,4} would return 2 as the most common int. B. Write mostCommon (same as above) that accepts an array of doubles, and returns the double that occurs most frequently. Consider any double values that are within 0.1%...

  • By using Java public static methods solve following problem Write a method called vowelCount that accepts...

    By using Java public static methods solve following problem Write a method called vowelCount that accepts a String as its only parameter, and returns an array int[5] containing the count of vowels a,e,i,o,u in that String, using ignoreCase. For example, vowelCount("") returns {0,0,0,0,0}, and for the callvowelCount("Bill Iverson") your method returns {0,1,2,1,0} because there is one 'e' and two 'i' vowels (ignore case) and one 'o' with zero counts for 'a' and 'u' vowels.

  • java code Write a method called reverse that takes an array of integers as an input...

    java code Write a method called reverse that takes an array of integers as an input and returns the same values in reverse order as the output. Test your method in the main.

  • JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The...

    JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The method should display the contents of the pets array on one line. Each name should be separated by a space. Use an enhanced for loop to iterate the array. Make sure to declare modifier, parameters and return values. Given an array String[] pets = {"Lucky", "Slinger", "Beast", "Trumpet", "Lulu", "Shadow", "Daisy"} A sample run when calling displayPets(pets) from main() would look like: Pets names:...

  • 11) Write a method (including header and body) that takes as an input an array of...

    11) Write a method (including header and body) that takes as an input an array of doubles and f three doubles containing the average, the maximum and the minimunm values of the input array. Test the program by calling the method from the main method. For example Input: 1 2 3 45 Output: 3 5 1 12) Write a Java method that takes a string as an argument and returns the reverse the string. Test the program by calling the...

  • Write a basic ARM program that takes a string as input, then outputs a string that...

    Write a basic ARM program that takes a string as input, then outputs a string that replaces all the vowels in the input string with 'x'. Vowels: a, A, e, E, i, I, o, O, u, U. **I am using DS-5 Eclipse Community Workspace with ARM assembly language.** The program should give the following input prompt: "Input a string: " Then, the program should output the string with the vowel(s) replaced with x. The program should terminate upon printing the...

  • sorted vowels Write a function that returns true if the vowels in the input string A...

    sorted vowels Write a function that returns true if the vowels in the input string A appear in non-decreasing order and false otherwise. You can assume this function is not case sensitive. If the string does not contain any vowels, it must return true. bool sorted_vowels (const char A)

  • Write a method in java named isValidEmail that takes a string as input parameter, and returns...

    Write a method in java named isValidEmail that takes a string as input parameter, and returns true if that string represents a valid email address, or false otherwise. An email address is considered valid if it follows this format “[email protected]”, where:  user123 represents a sequence of word characters (i.e., letters, digits, or underscore) whose length is between 1 and 10 (inclusive), but the first character must be a letter  domain represents a sequence of alphanumeric characters (i.e., letters...

  • Write a Java method called compare that takes two integers as input parameters and returns 1...

    Write a Java method called compare that takes two integers as input parameters and returns 1 if the first parameter is larger than the second parameter returns – 1 if the second parameter is larger than the first parameter, and returns 0 if the two parameters are equal.

  • Write function vowelCount2() that takes a string as input and counts and prints the number of...

    Write function vowelCount2() that takes a string as input and counts and prints the number of occurrences of vowels in the string. Vowels are a, e, i, o, and u. Implement the code in the file lab5.py. This function is very similar to the function of the problem 4.25, but the vowel information which did not appear in the string should not be printed. The printing order of the vowels is a, e, i, o, u. e.g.) >>> lab5.vowelCount2(‘augustana’) a,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT