Question

please use java Write a program that prompts the user to enter line of text (including...

please use java

Write a program that prompts the user to enter line of text (including whitespace). The program then replaces the following vocals with numbers: a = 1, e = 2, i = 3, o = 4, u = 5 and outputs the result to the console. The program does not consider case, so a = 1, A = 1, e = 2, E = 2, etc.

Example:
Input: Hello, how are you?
Output: H2ll4, h4w 1r2 y45?

The program must be error-free to get the points.

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

import java.util.Scanner;

public class sh {
public static void main(String[] args) {
  
Scanner in=new Scanner(System.in);
System.out.println("Enter sentence: ");
String sentence=in.nextLine();
char[] ch = new char[sentence.length()];
  
// Copy character by character into array
for (int i = 0; i < sentence.length(); i++) {
ch[i] = sentence.charAt(i);
}
for (int i = 0; i < sentence.length(); i++) {
if(ch[i]=='a' ||ch[i]=='A')
ch[i]='1';
if(ch[i]=='e' ||ch[i]=='E')
ch[i]='2';
if(ch[i]=='i' ||ch[i]=='I')
ch[i]='3';
if(ch[i]=='o' ||ch[i]=='O')
ch[i]='4';
if(ch[i]=='u' ||ch[i]=='U')
ch[i]='5';
}
String new_str = new String(ch);
System.out.println(new_str);
  
}
  
}

Add a comment
Know the answer?
Add Answer to:
please use java Write a program that prompts the user to enter line of text (including...
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
  • Write a Perl program that prompts a use to input a line of text. If the line of text mentions bot...

    Write a Perl program that prompts a use to input a line of text. If the line of text mentions both John and Smith, the program outputs “FOUND.” Otherwise, it outputs “NOT FOUND.” Write a Perl program that prompts a use to input a line of text. If the line of text has a word that is capitalized but not ALL capitalized, the program outputs “FOUND.” Otherwise, it outputs “NOT FOUND”. For example, if the user enters “Fred,” the program...

  • Very difficult and confusing assignment for C++ need help! Write a program that prompts a user...

    Very difficult and confusing assignment for C++ need help! Write a program that prompts a user to enter a line of text (including whitespace). Please use string object NOT C-string, a string library can be included. 1. Convert the input into uppercase and output the string to the screen. 2. Get the first and the last characters then appends the line with "I Love C++" and output the string to the screen. Example: Input: Hello, How are you? Output 1:...

  • Exercise #3: write a Java program that prompts the user to enter a sentence. The program...

    Exercise #3: write a Java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, O, o, I, i) c. the number of characters as numbers or special characters (other than English letters a.z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse: UAEU is the university of the...

  • Write a Perl program that prompts a use to input a line of text. If the...

    Write a Perl program that prompts a use to input a line of text. If the line of text has a word that is capitalized but not ALL capitalized, the program outputs “FOUND.” Otherwise, it outputs “NOT FOUND”. For example, if the user enters “Fred,” the program outputs “FOUND.” But if the user enters “fred” or “FRED,” the program outputs “NOT FOUND.”

  • C++ program by netBeans java language Exercise #2: Write a java program that prompts the user...

    C++ program by netBeans java language Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...

  • Write a complete Python program with prompts for the user for the main text file (checks...

    Write a complete Python program with prompts for the user for the main text file (checks that it exists, and if not, output an error message and stop), for any possible flags (including none), and for any other input that this program may need from the user: split has an option of naming the smaller files head_tail list the first 10 lines (default) and the last 10 lines (default) in order of the given text file flag: -# output #...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • Write a program in C++ that prompts the user to input the name of a text...

    Write a program in C++ that prompts the user to input the name of a text file and then outputs the number of words in the file. You can consider a

  • PLEASE complete this in java. Write a program that prompts the user to enter a file...

    PLEASE complete this in java. Write a program that prompts the user to enter a file name and displays the occurrences of each letter in the console window and in a file. Letters are case insensitive. Use “USAconst.txt” for input and “letterCount.txt” for output. Use try- catch blocks to handle checked exceptions. Here is a sample file output: is ወ The ወ ው The Enter file name: USAconst.txt The occurrence of A's is 2675 The occurrence of B's is 612...

  • write a java program that prompts a user to enter two different numbers, divide the first...

    write a java program that prompts a user to enter two different numbers, divide the first number by second and prints the result

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