Need Help with Java Program: Uppercase & Lowercase Conversion

  • Context: Comp Sci 
  • Thread starter Thread starter sankalpmittal
  • Start date Start date
  • Tags Tags
    Java Program
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 3K views
sankalpmittal
Messages
785
Reaction score
27
My teacher gave me a program in Java which none of us were able to do. So, I need help.

Homework Statement


We have to find the uppercase of the lowercase alphabets which the user inputs and vice versa. In case the character is special character, then it will leave blank space. It will work till the user wishes and the output of the program should be in front of the input. Example :

A a
v V
*
l L


Homework Equations


No equations.


The Attempt at a Solution


I did this program but the only thing I was unable to do was to get the output just in front of the input.
 
Physics news on Phys.org
sankalpmittal said:
My teacher gave me a program in Java which none of us were able to do. So, I need help.

Homework Statement


We have to find the uppercase of the lowercase alphabets which the user inputs and vice versa. In case the character is special character, then it will leave blank space. It will work till the user wishes and the output of the program should be in front of the input. Example :

A a
v V
*
l L


Homework Equations


No equations.


The Attempt at a Solution


I did this program but the only thing I was unable to do was to get the output just in front of the input.

For each character that you process you have one variable with the original character, and another variable with the capped (or uncapped) version of the letter. When you display the results, print the final version of the character, and then the original letter.
 
Mark44 said:
For each character that you process you have one variable with the original character, and another variable with the capped (or uncapped) version of the letter. When you display the results, print the final version of the character, and then the original letter.

That is okay but what our teacher has asked us to do is to print the capped( or uncapped ) version in front of the character inputted by the user. Means we don't have to print the user given character again.

User inputs : I
the output will be i in the same line. That is :

I i

I thought of another way but am unable to find the unicode of the up arrow key.
 
Hi sankalpmittal!

Standard console I/O does not allow for moving the cursor up.
To do so, you will need some kind of extension that requires you to bypass the standard console I/O functions.
It is certainly not an unicode character.

Usually it's best to avoid such extensions, since they do not always work.

Or if you want to make a neat user interface, create a graphics user interface (GUI).
That would not do what you requested though.
In Java you can create a GUI with the JFC/Swing package (google it).

If you really want to, you can use perhaps ANSI escape sequences.
(See: http://en.wikipedia.org/wiki/ANSI_escape_code).
Printing the string "\x1B[1F" should move your cursor to the beginning of the previous line.
But you'll have to try it out to see if it works for you.


I recommend what Mark already suggested: after the input, output a line that repeats the input.