How to move pointer in display to beginning of line.I don't want to create a new line.I want to take the cursor/pointer to the beginning in same line.

I have taken help of all possible combinations of System.out.print statements.

For example in the code below i want to print 70 spaces then print any character say "$",then take cursor back to beginning of the same line print 50 spaces and display another character say "#".

I have tried this one with several other combinations:-

class Test
{
  public static void main( String args[] )
  {
     for(int j=0;j<70;j++)
      {
        System.out.print(" ");
      }
      System.out.print("$"); 
      
     for(int j=0;j<50;j++)
     {
        System.out.print("\b");
     }
      System.out.print("$"); 
    
    
    }
}

How to move pointer in display to beginning of line.I don't want to create a new line.I want to take the cursor/pointer to the beginning in same line.

I don't believe this is "minor" at all. I certainly have never done it. Googling "java gotoxy" yields some good results, with most of them saying that a Java equivalent of this old C function does not exist or that you have to use jcurses or something similar.

http://sourceforge.net/projects/javacurses/

By using your code, I suppose you can move back 50 spaces and print the # sign, and then you can move forward 20 spaces and print the $ again.

This article has been dead for over six months. Start a new discussion instead.