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



Reply With Quote

Bookmarks