Results 1 to 2 of 2
  1. #1
    logieen is offline Member
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    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 "



    Java 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
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    When you get errors it is VERY IMPORTANT that you copy the full text of the message and post it here. The error message will have the line number in your program where the error occured.
    It looks like the following is outside of a method.
    prevCh='.';

Similar Threads

  1. String uppercase/lowercase
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-19-2007, 09:22 AM

Posting Permissions

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