Wednesday, October 11, 2017

for-loop(String replacement)

Challenge: Write a program that reads a line of input as a string and prints the string, with all vowels replaced by an underscore.


import java.util.Scanner;
class lab6_4
System.out.print("Enter string: ");
String myString = in.nextLine();
String[] vowels = {"a", "u", "o", "e", "i","A","E","I","O","U"};
for(String newString : vowels)
}      




{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);

    myString = myString.replaceAll(newString, "_");
System.out.println(myString);


}

No comments:

Post a Comment