Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
OK, reset time. counter is NOT the count of uppercase letters. It is your LOOP control. The comments don't say to update the loop control variable.

Back in your declarations, what variable did you define for the count of uppercase characters? And for lowercase characters? Increment those!

Todd
 
Code:
[color=red](first_letter == false)// reset the flag indicating...[/color]

forgetting here?

AND... this is NOT an assignment. It is a comparison. You want to assign false to the variable.

Not to be rude, but I really think it's time for you to find someone local to you ,to sit down with, and start over with Java from day 1 with you. You're not getting it.

Todd
 
OK, reset time. counter is NOT the count of uppercase letters. It is your LOOP control. The comments don't say to update the loop control variable.

Back in your declarations, what variable did you define for the count of uppercase characters? And for lowercase characters? Increment those!

Todd


Code:
while (counter < total) {

	this_char = sentence.charAt(counter);
	if (first_letter == true) {   // capitalize all first letter of each word 
		if (this_char >= 97 && this_char <= 122) {
                        
                        this_char -= 32; // convert to uppercase
                        System.out.print (this_char); 
                        upper++; //bump the count of upper case characters
                        first_letter == false// reset the flag indicating we will not be looking at a "first letter" next loop.
		}
		
		
	} 

	else {    //  this is not the first letter. Make sure it is lower case or a blank. 
            if (this_char >= 65 && this_char <= 122) {// if this is an upper case letter 
		this_char += 32;// convert it to lower case. 
		lower++; // update count of lower case letters. 
	}
 
Code:
import javax.swing.JOptionPane;

public class asgn3{
public static void main( String[] args )
{
String sentence = JOptionPane.showInputDialog(null,
"Enter a sentence");
boolean first_letter = true; 
char this_char; 
int upper = 0;
int lower = 0;
int space = 0;
int other = 0;
int counter = 0;
int total = sentence.length();//declared all the variables


while (counter < total) {

	this_char = sentence.charAt(counter);
	if (first_letter == true) {   // capitalize all first letter of each word 
		if (this_char >= 97 && this_char <= 122) {
                        
                        this_char -= 32; // convert to uppercase
                        System.out.print (this_char); 
                        upper++; //bump the count of upper case characters
                        first_letter == false;// reset the flag so next loop won't look at first letter. 
		}
		
		
	} 

	else {    //  
            if (this_char >= 65 && this_char <= 122) {// if this is an upper case letter 
		this_char += 32;// convert it to lower case. 
		lower++; // update count of lower case letters. 
	} 

            
	// print out the letter. 
        else { 
              if (this_char == 32)  // if this is a blank
                  
                         // set the flag that tells the loop to capitalize the first letter
		space++;// update count of blanks 
                  
                  
                  
        } 
		
	
	// print the character withut a line return. 

	counter++;
	
	} 

System.out.println("Total: " + total);
System.out.println("Upper: " + upper);
System.out.println("Lower: " + lower);
System.out.println("Space: " + space);
System.out.println("Other: " + other);
System.out.println("Total: " + total);


} // end main
} // end of program

so i think i am getting there? i still dont see what i have to do to that first_letter == false though. i thought you said it was right at first, and now it is not.
 
Code:
first_letter == false;// reset indicating we will not be looking at a "first letter" next loop.

this one line is really screwing me over

i cant seem to figure it out
 
There is a difference between

Code:
first_letter == false;

which is a comparison and evaluates to either true or false (is the value assigned to first_letter equal to false?), and

Code:
first_letter = false;

which assigns the value false to first_letter.
 
Not to be rude, but I really think it's time for you to find someone local to you ,to sit down with, and start over with Java from day 1 with you. You're not getting it.
todd++

Office hours with the prof, tutoring, other students, IRC, forums...preferably something in person..is not a bad idea. Sometimes you just have to talk things over with someone who can help you go in the right direction. You need have a good foundation to start with - insufficient knowledge of loops (among other things)? Fix that right now before you get even more lost in class. Asking for help on every single assignment is going to do you no good at all, especially when you have everyone gently prodding you towards the right answer.
 
Here you go.

Hey there. This is the simplest way to go about the task you're trying to accomplish.

import javax.swing.JOptionPane;

public class Capitalize
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Enter a word.");
String firstLetter = input.substring(0,1);
String remainder = input.substring(1);
String goodInput = firstLetter.toUpperCase() + remainder.toLowerCase();
JOptionPane.showMessageDialog(null, goodInput);
}
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.