This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Programming Project?

 
Devon Lewis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have question on a programming project. Here is the description : Write a program (Class name Pr1a) that prompts user to enter a sentence. The program should display each character on the screen except space character (‘ ‘). For each character, there are three possible outputs to display. They are “Upper case”, “Lower case”, and “Not a letter”. Note that if the character is a space character, then you do not display space character, and you do not display any of the three possible outputs. The program also must show total letter count, total lower case count, and total upper case count. For the total letter count, do not count the space characters, or Non-letter characters.

I was wondering how I would arrange the if else statements, in order to get the output to print whether there upper case, lower case or not a letter.

Here is my code :

 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Devon,

In the future, please UseCodeTags and also not so many blank lines.

I think you're looking for a basic if-else if-else structure like:



Maybe you need an extra else-if in there to handle space characters, but it's best to start simple and then enhance until you meet all the requirements.
 
Devon Lewis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I am trying to get the output to look something like this :

D : UpperCase

e - Lower Case

v- lower case

o- lower case

n - lowercase

!- not a letter.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and...what problem are you having?

Things generally work best around here if you ask SPECIFIC questions. Remember, we can't read your mind. We can't read your code (unless you post it). You should try and make it as EASY as possible for someone to help you.

 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what you're missing is a loop structure. Have you learned about loops yet?
 
Devon Lewis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:and...what problem are you having?

Things generally work best around here if you ask SPECIFIC questions. Remember, we can't read your mind. We can't read your code (unless you post it). You should try and make it as EASY as possible for someone to help you.

The issue im having is trying to get the output to say whether each specific character in the sentence I enter, is uppercase, lowercase or not a letter. Here is my code again :

import java.util.Scanner;

public class Pr1a
{

public static void main(String[] args)
{

Scanner st = new Scanner(System.in);

String l = " ";


System.out.print("Please enter a sentence: ");

l = st.next();





char x ;

x = ' ';




if(x>='a' && x<='z'){

System.out.print( " : Lowercase" );

System.out.println(l.toLowerCase());




l = st.next();

}


else if(x>='A' && x<='Z') {

System.out.print(" : Uppercase" );

System.out.println(l.toUpperCase());





l = st.next();


}

}

}
 
Henry Wong
author
Marshal
Pie
Posts: 21121
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Devon Lewis wrote:
fred rosenberger wrote:and...what problem are you having?

Things generally work best around here if you ask SPECIFIC questions. Remember, we can't read your mind. We can't read your code (unless you post it). You should try and make it as EASY as possible for someone to help you.

The issue im having is trying to get the output to say whether each specific character in the sentence I enter, is uppercase, lowercase or not a letter.


The beginning of your code asks for a sentence, but the rest of your code only handles one letter. As someone already mentioned, you will need to have some sort of loop -- as a sentence is made up of lots of letters.

Henry
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there's no loop in that code. Your book or class must have discussed this structure, or you can just Google for "java while loops".

Also, code has to go between the opening and closing tags. Probably the easiest way to do that is to paste in your code, and then highlight it before hitting the Code button.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic