Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to replace the vowels with a user input Character

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to replace the vowels with a user input Character

    I need to replace all the vowels with the letter that the user input when they choose option 2
    how do i get the user input and replace?
    Heres what i have for my code so far

    `
    import java.util.Random;
    import java.util.Scanner;

    public class ArrayLab
    {
    public static void main( String[] args )
    {
    final int SIZE = 10;
    char letters[]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
    char replace;

    Scanner in = new Scanner(System.in);
    // print menu
    for (int i = 1; i <= 5; i++)
    System.out.println(i + "Choose Option" + i);
    System.out.println("6 to Quit");
    // handle user commands
    boolean quit = false;
    int menuItem;
    do {
    System.out.print("Choose option: ");
    menuItem = in.nextInt();
    switch (menuItem) {
    case 1:
    System.out.println("You've chosen to display");
    System.out.println( letters );
    break;
    case 2:
    System.out.println("You've chosen to replace");
    replace = in.toCharArray();
    break;

    case 3:
    System.out.println("You've chosen to shift right");
    // do something...
    break;
    case 4:
    System.out.println("You've chosen lowercase");
    // do something...
    break;
    case 5:
    System.out.println("You've chosen average of array");
    // do something...
    break;
    case 6:
    quit = true;
    break;
    default:
    System.out.println("Invalid choice.");
    }
    } while (!quit);
    System.out.println("Quitting");

    }
    }`


  2. #2
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to replace characters in Array with user input Characters

    I need to replace all the vowels with the letter that the user input when they choose option 2
    how do i get the user input and replace?
    Heres what i have for my code so far

    `
    import java.util.Random;
    import java.util.Scanner;

    public class ArrayLab
    {
    public static void main( String[] args )
    {
    final int SIZE = 10;
    char letters[]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
    char replace;

    Scanner in = new Scanner(System.in);
    // print menu
    for (int i = 1; i <= 5; i++)
    System.out.println(i + "Choose Option" + i);
    System.out.println("6 to Quit");
    // handle user commands
    boolean quit = false;
    int menuItem;
    do {
    System.out.print("Choose option: ");
    menuItem = in.nextInt();
    switch (menuItem) {
    case 1:
    System.out.println("You've chosen to display");
    System.out.println( letters );
    break;
    case 2:
    System.out.println("You've chosen to replace");
    replace = in.toCharArray();
    break;

    case 3:
    System.out.println("You've chosen to shift right");
    // do something...
    break;
    case 4:
    System.out.println("You've chosen lowercase");
    // do something...
    break;
    case 5:
    System.out.println("You've chosen average of array");
    // do something...
    break;
    case 6:
    quit = true;
    break;
    default:
    System.out.println("Invalid choice.");
    }
    } while (!quit);
    System.out.println("Quitting");

    }
    }`

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to replace characters in Array with user input Characters

    Duplicate topic.

    Duplicate response: Please don't post duplicate topics. Read the Announcement topic at the top of the sub-forum to learn how to post your code correctly and other useful tips for newcomers.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to replace the vowels with a user input Character

    Duplicate topic.

    Duplicate response: Please don't post duplicate topics. Read the Announcement topic at the top of the sub-forum to learn how to post your code correctly and other useful tips for newcomers.

Similar Threads

  1. Trying to validate a character user input in an array ?
    By lizzy2 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2013, 03:04 PM
  2. User Input help
    By dx2731 in forum Java Theory & Questions
    Replies: 3
    Last Post: May 13th, 2013, 12:46 AM
  3. User Input help
    By lanmonster in forum What's Wrong With My Code?
    Replies: 20
    Last Post: January 20th, 2013, 10:44 AM
  4. Take user input
    By frabbi.cse in forum Java Theory & Questions
    Replies: 1
    Last Post: July 22nd, 2012, 12:48 PM
  5. Valid user input
    By ChristopherLowe in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM

Tags for this Thread