answersLogoWhite

0

/**

* Prints all characters in str that are consonants.

*/

public static void printConsonants(final String str) {

System.out.println("Consonants in '" + str + "'");

for (final char ch : str.toCharArray()) {

// Remember that a consonant is any character that is not a vowel.

if (!isVowel(ch)) {

System.out.println(ch);

}

}

}

/**

* Prints all characters in str that are consonants, dismissing duplicates.

*/

public static void printUniqueConsonants(final String str) {

System.out.println("Consonants in '" + str + "'");

// Store consonants in a Set to avoid printing duplicates.

final Set<Character> charSet = new TreeSet<Character>();

for (final char ch : str.toCharArray()) {

// Remember that a consonant is any character that is not a vowel.

if (!isVowel(ch)) {

charSet.add(ch);

}

}

System.out.println(charSet);

}

/**

* Returns true if ch is a vowel.

*/

public static boolean isVowel(final char ch) {

return ch 'u';

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Where could someone find an example of Java string comparisons?

There are many sites to find examples of Java string comparisons. Java Revisited, Java Coffee Break, Alvin Alexander, Stack Overflow and Lee Point are a few to start with.


How can find the length of a string in java without using fun?

Use length() method. Example: "java".length();


Where can one find a tutorial on java string array?

There are many ways to find tutorials on Java string array. You can purchase the digital tutorials at a local computer store. There are also books you can check out at your local library.


Where can one find information on converting string to int java?

One can find information on converting string to int in Java by visiting the Stack Overflow website. This website is free to browse and has lots of information on this topic.


Where could someone find a tutorial explaining java string format?

You can go to the library to find a book on java string format that will explain it. You can also go to different places like Oracle or Homeandlearn to get more information on the subject.


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


Write a java program to input a string and find the total number of uppercase letters in the string?

The code is given at the bottom. This code requires JAVA 1.5+ version to be compiled.This is very simple program. We ask user to input string and later we just iterate through all the character in the string. We use Character.isUpperCase() static method to check is the character we are checking is upper case if so we increase count variable by one. After iteration is done we print count variable and application quits.Note: for statement was introduced in 1.5 JAVA version.Example of usage:david-mac:~ david$ java TestEnter string: This is A Test String.Your string has 4 upper case letters.-------------------------import java.io.*;import java.lang.*;public class Test{public static void main(String[] args)throws IOException{BufferedReader in = new BufferedReader(new InputStreamReader(System.in));System.out.print("Enter string: ");String userString = in.readLine();int count = 0;for (char ch : userString.toCharArray()){if (Character.isUpperCase(ch)){count++;}}System.out.println("Your string has " + count + " upper case letters.");}}


Java source code to find prime number?

/* Program to Find whether number is Prime or Not. */ class PrimeNo{ public static void main(String args[]){ int num = Integer.parseInt(br.readLine()); int flag=0; for(int i=2;i


Which of these methods of string class is used to obtain character at specified index?

You don't specify "these methods", but chances are what you're looking for is the charAt method


How do you use indexOf in java?

indexOf is a method of the String class. Since the indexOf method is overloaded, I will be using the indexOf(String str) version in this example. According to the API Documentation, this method "Returns the index within this string of the first occurrence of the specified substring." So, if you wanted to find the position of the letter 'v' in the String 'Java' and print it out, you would do this: String str = "Java"; int i = str.indexOf("v"); System.out.println(i); If the character you passed in the indexOf method does not exist in the String, indexOf would return a -1 (negative one).


Where could one get advice on converting int to string using java?

There are a number of technology sites that offer good advice on converting int to string using Java. One can find helpful advice on sites such as Stack Overflow, eHow and the Oracle website.


How do you write a java program for finding multiligual languages?

You can use Java's built-in functions to write a code that will find multilingual languages.