Hello, I need to convert the first letter of each sentence to a capital letter if the
user inputs a lower case letter. I'm having a difficult time trying to figure out where I'm going wrong at so here's my pseudo code.
import java.util.Scanner;
public class Cap {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String yourSentence = "Please enter a string";
System.out.println(Cap(yourSentence));
yourSentence = keyboard.next();
//yourSentence = JOptionPane.showInputDialog(Cap(yourSentence)); (this was my original display, but I decided to use the System.out instead)
}
// method to cap 1st letter of the sentence
public static String Cap(String str) {
StringBuffer temp = new StringBuffer(str);
int[] numberOfCaps = new int[1];
for (int i=1; i<numberOfCaps.length; i++) {
numberOfCaps[i] = (int)(Math.random() * temp.length());
}
for(int x=1; x<numberOfCaps.length; x++) {
temp.setCharAt(numberOfCaps[x], Character.toUpperCase(str.charAt(numberOfCaps[x])));
}
return temp.toString();
}
}
Edited by: pbsacct_1 on Feb 5, 2009 9:40 PM
Edited by: pbsacct_1 on Feb 5, 2009 9:40 PM