Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Java program

  1. Apr 21, 2012 #1
    My teacher gave me a program in Java which none of us were able to do. So, I need help.

    1. The problem statement, all variables and given/known data
    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

    2. Relevant equations
    No equations.

    3. 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.
  2. jcsd
  3. Apr 22, 2012 #2


    Staff: Mentor

    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.
  4. Apr 23, 2012 #3
    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.
  5. Apr 25, 2012 #4

    I like Serena

    User Avatar
    Homework Helper

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook