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("$"); 
    
    
    }
}

Recommended Answers

All 3 Replies

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.

I don't think they have anything in java's supplied api's. Because Java's platform independent, I don't think they can have a function like gotoxy() in c

at the bottom of this is some good references.
http://forums.sun.com/thread.jspa?threadID=433261

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.