Right justify output

Hi, how do u right justify the output for the below code - not GUI based.
for (int x=7; x<=10; x++){
System.out.println(x);
The output is:
7
8
9
10
but i want this format:
(space)7
(space)8
(space)9
10
thank you.

Well, the %d format specifier wants an integer, and you're passing it a string.
Calling a method as the value passed to printf should not in itself be a problem.
You probably want to do something more like:
System.out.printf("%02d    %d%n", x, test());Depending on what test() returns.

Similar Messages

  • Right Justifying String output

    I have created a program to create directories and files and navigate them. The problem im stuck on is that
    I'm trying to print the working directory (as a subdirectory) so Im wanting to right justify the current directories name, then call the parent Directory and print its name on the left side of it etc....until I get to root directory.
    How do I output the String to the terminal in this fashion ?
    Cheers

       public static final int FILL_TO_LEFT = 0;
       public static final int FILL_TO_RIGHT = 1;
       /** Right alignment of string based on the passed width */
       public static String alignRight(String origstr, int width) {
          String retstr = origstr;
          if (retstr == null) retstr = "";
          retstr = retstr.trim();
          if (width > retstr.length()) {
             retstr = fillSpaces(retstr,width,FILL_TO_LEFT);
          else {
             if (width < retstr.length()) {
                retstr = retstr.substring(0,width);
          return retstr;
       /** Fill string with a char based on filling type */
       public static String fillChar(String origstr, int width,
                                     String fillchar, int filltype) {
          String retstr = origstr;
          if (retstr==null) retstr = "";
          retstr = retstr.trim();
          switch(filltype) {
             case FILL_TO_LEFT:  {
                                   while (retstr.length()<width) retstr = fillchar + retstr;
                                   break;
             case FILL_TO_RIGHT: {
                                   while (retstr.length()<width) retstr = retstr + fillchar;
                                   break;
          return retstr;
       /** Fill a string with spaces based on passed width and filling type */
       public static String fillSpaces(String origstr, int width, int filltype) {
          return fillChar(origstr, width, " ", filltype);
       }

  • Tab delimited and Right justified fields

    Hi
    My requirement is to produce an output file where the line items consists of 5 fields of variable lengths and all of them are tab delimited and right justified at the same time
    for eg.
    ABC       123456ghtje  4567.45678   67.45678  pqr
    where all the values in the first field 'ABC' and 2nd field '123456ghtje' are right justified and are tab delimited and asme is the case for '4567.45678' , '67.45678' and 'pqr'
    they are all separated from each other by a tab but are not fixed lengths
    How can i achieve that ? i am using File Receiver Adapter ??
    Can it be done without Adapter Module ?
    Thanks
    Dev
    Edited by: sd on Feb 22, 2010 2:25 PM
    Edited by: sd on Feb 22, 2010 2:26 PM

    > they are all separated from each other by a tab but are not fixed lengths
    When thay are not fixed length fields, why do you have to worry about left or right justification? In delimetted files, you would only have the delimitter between the fields. You do not need to fill spaces for justifying them.
    VJ

  • Unable To Print Right Justified from Customize Local Layout (Alt+F12)

    Hi,
    Problem I am having is giving me nightmares. I am able to print hebrew text abap list in sap 4.5b. But when i change the Character Set of language from "Customize Local Layout"  (Alt+F12) to Hebrew (Right Justified) the preview shows up correcctly.  But when I print from an actual printer, it still shows output as (Left Justified). Can someone please help!!!!!!

    Hi
    Apologies for replying late. The printer is unicode enabled however, since we are on a non-unicode version of SAP (4.5b) it wouldnt really matter. We are printing Hebrew language. Its always coming out as left justified. We want it to print right justified.
    Awaiting some solution....

  • Right Justify result...

    Hello,
    I have the following query that I am trying to right justify the number results. I've tried to change the number by using "to_char" so that it would automatically justify to the right, however this did not work. here is my query...
    Select to_char(val_11, '9999999.99') where x = y
    Please help if you can.
    Thanks.

    In what way isn't it right justified?
    SQL> select to_char(1234, '999999.99') from dual;
    TO_CHAR(12
       1234.00
    SQL>Formatting of output is dependant on the display environment, not the code producing the data.
    :o/

  • Using Right-justified and left zero-filled condition in message mapping of

    Hi,
    My Interface is outbound Interface.
    Suppose source field named 'MobNumber' is mapped with Target field named 'MobileNumber'.Condition is AS IS(Right-justified and left zero-filled).
    How should i do this mapping?
    Thanks,
    Sanghamitra

    Hi Sanghamitra,
         Similar question ahs been answered earlier in this thread
    Re: Message Mapping using Left justified, right blank/space filled
    just replace the filler variable by zero in my post
    One small request, if you think your questions are being answered correctly and properly, please kindly, if possible, close down the threads. This way forum members/users  who later look up for solutions to similar problem, they know for sure that the problem was finally solved, with the solutions provided in the thread.   
    regards
    Anupam
    Edited by: anupamsap on Aug 3, 2011 11:27 AM

  • Cursor Doesn't display in numeric right justified fields

    We have an aplication that we deployed at a client. Normally the cursor blinks in the field that has focus. However, at this particular client the cursor doesn't show on numeric fields that are right justified. The user can type in the values though. Please help.
    Alok

    Hello,
    Maybe you can increase the width of field.
    Regards,
    George
    We have an aplication that we deployed at a client. Normally the cursor blinks in the field that has focus. However, at this particular client the cursor doesn't show on numeric fields that are right justified. The user can type in the values though. Please help.
    Alok

  • FW: Caret Location Right Justified for LI when using HTMLEditorKit

    It appears that when using the HTMLEditorKit and inserting any sort of list
    item (ordered list or unordered list) into a view (while in edit mode), the
    caret is initially *---------| right justified with respect to the bullet
    image. If the identical html is loaded all at once however the caret is *-|
    left justified with respect to the bullet image. Is this a bug in
    HTMLEditorKit?

    Sure it is. In this special case IBM's JDK does a better job (at least under Linux).
    Generally I'm totally disappointed by the whole HTML package. I've been trying to implement a really primitive WYSIWIG-HTML-editor which understands <p>, <ul>, <h1> <b>, <i> and <a href>. It is a nightmare!
    - Dynamically modifying the document's structure (e.g., by making a <li> out of a <p>) works more or less, but you have absolutely no control over caret movement, and different JDK's make it differently!
    - The HTMLDocument inserts crude "extra-tags" (e.g., those <p-implied>'s. You never know exactly the structure of your document, and after a long debugging session you notice that the HTMLDocument was bluntly inserting yet another artificial element you did not specify. No docs at all what's going on.
    - It is nearly unbelievable how complicated so simple things like
    are internally modelled.
    - Frankly spoken: The whole document model sucks. Has to be harmonized with XML, DOM, JDOM, and all those nice new technologies where Java does a good job (unless you need a GUI...)
    If anybody has an idea to make it properly -> pls let me know
    thx
    Karl

  • How to Right Justify text on Ipod

    My ipod has been through some wear and tear, long story short, the screen is "cracked" so to speak down the middle and from the middle of the screen to the left side i cannot see anything. I'm trying to figure out how to right justify all of the text so that i can actually use my ipod and search songs

    You can't change the layout of any part of the iPod OS. Sorry. You might want to consider getting the screen replaced. There are lots of third party repair outfits that charge less than Apple to so the job.

  • Cursor not right-justifying in Oracle Forms 11.1.1.6.0

    Hi All,
    A user notice during testing that 'cursor not right-justifying' in a field on a form. There were not such problem in the old forms enviroment 10.1.2.0.2 and clients running JInitiator 1.3.1.22. The new forms enviroment is Oracle weblogic 10.3.6, Oracle forms and report 11.1.1.6.0, using forms demo pack cursorpos.jar and demo90.jar, have try the 11g demo pack but still the same problem, any ideas?
    Thanks
    Ola

    A user notice during testing that 'cursor not right-justifying' in a field on a form.What exactly do you mean by "cursor not right-justifying"?
    You will find noticable differences between the way the Oracle Jinitiiator and Oracle (Sun) Java work. Remember, the Jinitiator was based on the Sun JRE/JDK 1.3 and Forms 11g will be using either Java 1.6.0 or 1.7.0.
    Craig...

  • Sort options right justified in list view

    New to Maverick's, but I can't get my finder window to "stick" with the layout of the "sort options". My biggest beef is that I have the "Name" sort far left followed by "Date modified", etc.. yet every day in every new finder window, the 2nd sort jumps to right justified. I want this sort option to stick to the left alongside name. I use large monitors and scrolling over everytime to drag the sort modifier to the left is frustrating. Is there a solution?

    My guess would be the Images folder (Pictures in English) is designed to have the special, contextual grouping types.
    I don't know why they couldn't make them available in the dropdown menu, also, but they're not.
    I did a little testing and found if I called it Pictures unsorted, the options were available, but if I called the folder unsorted Pictures, they weren't.
    Try naming the folder starting with Images
    Edit: If I select the dimension and resolution column headers in the folder, then change the name of the folder, the columns are retained.

  • How to get search help results in RIGHT-JUSTIFIED column

    I am writing a search help with search help exit. Therefore, I use a table lets say tabA. I don't need all fields of tabA but need some further fields which I fill during exit.
    tabA does not have currency or number fields.
    I need a currency field and use a char20 field of tabA instead. filling of this field and showing results is o.k., but of-course it is shown left-justified.
    I did not find any fields of shlp-fielddescr which sounds like left/centered/right-alignment. Another try was to fill char20 field with leading '_' signs - that looked terrible and was not right-justified either, because of not fixed-size font.
    Let's resume: there is no number or currency field which I can use. The shown results appear in a column of not fixed-size font.
    Any other idea?

    Hi, I have the same problem. Did you get to resolve it? . Thanks

  • Images in smart build open right justified

    Has anyone else seen this.
    I've just opened an existing Keynote08 file in 09. And all my smart build push images have become right justified and off center. I can't find anyway of putting them back into the center. Can anyone help?

    Have a look here. Only workaround I have found is to re-do the build. Send feedback to Apple via the Keynote Menu.

  • How to align Hgrid column(messagestyledtext) header text to right justified

    Hi All,
    I have a Hgrid table and i am using five columns in hgrid table.. I need to display column header text right justified. but by default it is left justified.
    Can any one tell me how to do it..
    Its very urgent.. Please help me out..
    Regards,
    Babu

    Use
    OAHGridBean GeneralHgrid=(OAHGridBean)webBean.findChildRecursive("<hgrid item name>");
    GeneralHgrid.prepareForRendering(pageContext);
    DataObjectList tableColumnFormats =GeneralHgrid.getColumnFormats();
    DictionaryData tableColumnFormat = (oracle.cabo.ui.data.DictionaryData)tableColumnFormats.getItem(pageContext.findChildIndex(GeneralHgrid, "<item id of item attached in hgrid column>"));
    tableColumnFormat.put(COLUMN_DATA_FORMAT_KEY, <enter format>);
    see below:
    �� TEXT_FORMAT (textFormat)- column content is Start justified.
    �� NUMBER_FORMAT (numberFormat)- column content is Right justified.
    �� ICON_BUTTON_FORMAT (iconButtonFormat)- column content is center justified.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • DW Right-justifying the index for one site only

    Dreamweaver has suddenly started showing the directory for one of my sites as right-justified:
    Does anyone know how I can get this back to left-justified?
    Thanks
    Steve

    toonbone23 wrote:
    ...Adobe who know exactly what causes this. Don't they ever visit the forum?.
    Steve
    I'm not sure they do!
    This is a user forum.  I htink if you want an answer to your question, you might like to consder raising a support ticket.  I come here quite a bit, and I have never noticed anyone ever having the same thing happen to them.
    Martin

Maybe you are looking for

  • "Movie not loaded..." swf error on html

    Hi everybody! I have a problem when i export a swf and html in flash, because when i upload it to my server and try it online i get the message "Movie not loaded..." when i click in a blank window where it should have played. In the activity window i

  • Daily Online Backup Error

    Hi Experts, Backup platform : HP Storage Data Protector Manager (HP UX B.11.31) Backup status Error : 0005 Error during processing Detail log:                    bedrppqy.dbv                                                                            

  • Not the supposed 7 hours as advertised

    Hey all, I recently bought a MacBook Pro for college, and for the most part I'm really pleased with it. However, a big reason I bought this computer is because of it's advertised 7 hour battery life. Since I got it yesterday, I've kept it plugged in,

  • Combining a security update with Photos?

    I am confused. Generally, if there is an available update, esp. a security update, either Apple tells me or just goes ahead and does it. For no particular reason, I looked to see if there were any available updates. I found 2 or 3, depending on how y

  • Using iTunes to update apps that are over 20mb

    I am trying to update 3 apps, which are over 20mb, by connecting to iTunes.  My phone syncs but it does not update the apps.  I checked my available for downloads option and it says it's empty.  How do I get the apps to update?  Thanks!