PDA

View Full Version : UpperCase problem



logieen
08-03-2008, 10:06 PM
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='.';




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;
}

}


}

peter_budo
09-14-2008, 12:34 PM
Once you create character variable you have to initialize in same time so your code

char prevCh;
prevCh='.';
should be

char prevCh='.';