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: Write a program to convert all vowels to capital letter in a sentence?

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    22
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Unhappy Write a program to convert all vowels to capital letter in a sentence?

    i am new to programming skills it may be silly question for experience but for me it's new thing. actually i tried a lot but i am facing problem when i trying to take input through Scanner.
    if i will take input a sentence directly as a string it's working . but when i am trying with Scanner the first word is showing next are not showing

    public class Demo2
    {
    public static void main(String[] args)
    {
    String s1="hi how are you";
    s1=s1.replace('a', 'A');
    s1 =s1.replace('e', 'E');
    s1 =s1.replace('i', 'I');
    s1 =s1.replace('o', 'O');
    s1 =s1.replace('u', 'U');
    System.out.println(s1);
    }
    }

    O/P--hI hOw ArE yOU

    this is working properly.

    but when i trying with Scanner i am facing problem.



    public class Demo2
    {
    public static void main(String[] args)
    {
    java.util.Scanner scn= new java.util.Scanner(System.in)
    String s1=scn.next();
    s1=s1.replace('a', 'A');
    s1 =s1.replace('e', 'E');
    s1 =s1.replace('i', 'I');
    s1 =s1.replace('o', 'O');
    s1 =s1.replace('u', 'U');
    System.out.println(s1);
    }
    }


    o/p-- hI


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Write a program to convert all vowels to capital letter in a sentence?

    Take a look at the API for Scanner: Scanner (Java Platform SE 8 )

    What does the next() function return? Have you tried printing out the value of s1 after you read it in?

    Hint: is there a method in the Scanner class that returns a whole line instead of just the next word?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    22
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Write a program to convert all vowels to capital letter in a sentence?

    thanks for your valuable tips... i got it.....


    import java.util.Scanner;

    public class Demo2
    {
    public static void main(String[] args)
    {
    Scanner scn=new Scanner(System.in);
    System.out.println("enter the sentence");
    String s1=scn.nextLine();
    s1=s1.replace('a', 'A');
    s1 =s1.replace('e', 'E');
    s1 =s1.replace('i', 'I');
    s1 =s1.replace('o', 'O');
    s1 =s1.replace('u', 'U');
    System.out.println(s1);
    }

    }

    op--enter the sentence
    hi how are you
    hI hOw ArE yOU


    thank you very much

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Write a program to convert all vowels to capital letter in a sentence?

    This probably goes outside the bounds of this assignment, but perhaps something interesting to think about is that Y is sometimes a vowel as well: When is "Y" a vowel? - English Language & Usage Stack Exchange
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 2
    Last Post: February 10th, 2014, 05:24 AM
  2. Convert Scores into letter Grades
    By noixam123 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 12th, 2013, 06:48 AM
  3. [SOLVED] Hangman Program Java: Comparing the User's Guess with Another String Letter by Letter
    By theonlydvr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 29th, 2013, 05:35 PM
  4. How to I convert this Sentence String to StringBuffer?
    By iCitationNeeded in forum Java Theory & Questions
    Replies: 4
    Last Post: May 22nd, 2012, 11:45 AM
  5. Sentence and Letter Count Program
    By velop in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2010, 11:10 PM