---
title: "easy way to find vowels and print them in JAVA"  
description: "easy way to find vowels and print them in JAVA"  
author: "Jayden Bell"  
published: 2014-11-05  
updated: 2014-11-05  
canonical: https://www.mindstick.com/forum/2516/easy-way-to-find-vowels-and-print-them-in-java  
category: "java"  
tags: ["for loop", "loop"]  
reading_time: 2 minutes  

---

# easy way to find vowels and print them in JAVA

Hey this is my first time [posting](https://www.mindstick.com/forum/34719/cross-page-posting)! I got my [program to print](https://www.mindstick.com/forum/157407/javascript-program-to-print-all-prime-number-between-two-intervals) out the vowels from an [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) from [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) but I feel like I have repeated myself a lot in the [for loop](https://www.mindstick.com/forum/12568/android-for-loop-not-working-in-main-thread). Is there a quicker way to do this? Also is this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) readable and in the [correct format](https://www.mindstick.com/forum/72/input-string-was-not-in-a-correct-format)?\

```
import java.util.Scanner;ublic class Task09 {public static void main(String[] args) {    Scanner input = new Scanner(System.in);   String vowels ="";   String answer= input.next()   for(int i = 0 ;i<answer.length();i++)   {       char answerPosition = answer.charAt(i);       if (answerPosition =='a'           ||answerPosition  =='e'           ||answerPosition  =='i'           ||answerPosition =='o'           ||answerPosition =='u'           ||answerPosition =='A'           ||answerPosition =='I'           ||answerPosition =='O'           ||answerPosition =='U')        {              vowels += answerPosition + " ";        }     } }
```

```
import java.util.Scanner;ublic class Task09 {public static void main(String[] args) {    Scanner input = new Scanner(System.in);   String vowels ="";   String answer= input.next()   for(int i = 0 ;i<answer.length();i++)   {       char answerPosition = answer.charAt(i);       if (answerPosition =='a'           ||answerPosition  =='e'           ||answerPosition  =='i'           ||answerPosition =='o'           ||answerPosition =='u'           ||answerPosition =='A'           ||answerPosition =='I'           ||answerPosition =='O'           ||answerPosition =='U')        {              vowels += answerPosition + " ";        }     }System.out.println("The vowels are:" + vowels);input.close(); }}
```

## Replies

### Reply by Mark M

Try this:

```
  String newString = answer.replaceAll("[^AaeEiIoOuU]", "");
  System.out.println(newString);
```

You wont need for loop as well and your code would be compact and sweet.


---

Original Source: https://www.mindstick.com/forum/2516/easy-way-to-find-vowels-and-print-them-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
