Results 1 to 2 of 2

Thread: UpperCase problem

  1. #1
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default UpperCase problem

    Hello everyone .....

    I am new in java i start learn it from 3 weeks ago so i don't know much abut java .
    i want to write a program that ask the user to enter his/her name and the program will print the first name as it is and the last name will be in UpperCase .

    the code it print this error " <identifier> expected "in this line prevCh='.';



    Code:
    import javax.swing.*;
    public class PrintUser
      {
    
        public static void main(String[]args)
        {
            String names=JOptionPane.showInputDialog(null,"Enter your Name :");
            System.out.println(names);
            UserName r=new UserName();
          JOptionPane.showMessageDialog(null,names);
         System.out.println();
        }
        
    }
    
    class UserName
    {
    
       char ch;
       char prevCh;
       	String names;  
              int i;        
           prevCh='.';
              void r(String[]args);
      {
      
              for (i=0;i<names.length();i++ ) 
              	{
                 ch = names.charAt(i);
                 if ( Character.isLetter(ch)  &&  ! Character.isLetter(prevCh) )
                    System.out.print( Character.toUpperCase(ch) );
                 else
                    System.out.print(ch);
                 prevCh = ch;  
               }
             
           }
            
            
    }

  2. #2
    Join Date
    Sep 2008
    Location
    London or Slovakia
    Posts
    27
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    Once you create character variable you have to initialize in same time so your code
    Code:
    char prevCh;
    prevCh='.';
    should be
    Code:
    char prevCh='.';

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •