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 (;

    myString = myString.replaceAll(newString, "_");


No comments:

Post a Comment