<tutorial title="Formatting Integers" ht="1">
 <shell lang="java" className="Demo" import="shells.xml#null"/>
 <question className="Demo" title="Printing an integer">
  <blurb lang='java'>
  <p>
  The printf method takes a format string as the first parameter.
  This string is printed but following parameters replace the % placeholders.
  </p>
  <p>%d is used for decimal numbers.
  </p>
  <table>
  <tr>
   <td class='imper'>Format</td>
   <td class='imper' style="width:6em">Code</td>
   <td class='imper'>Meaning</td></tr>
  <tr><td>Simple</td>
   <td><code>%d</code></td><td>A simple decimal number</td></tr>
  <tr><td>Right aligned</td>
   <td><code>%5d</code></td><td>Print right aligned in 5 characters.
        Fill any unused characters with spaces.</td></tr>
  <tr><td>Leading zeroes</td>
   <td><code>%05d</code></td><td>Print right aligned in 5 characters.
        Fill any unused characters with zero.</td></tr>
  <tr><td>Hexadecimal</td>
   <td><code>%x</code></td><td>Print as a hexadecimal (base 16) number.
        </td></tr>
  <tr><td>With commas</td>
   <td><code>%,d</code></td><td>Use , to separate thousands.
        </td></tr>
  </table>
  </blurb>
  <blurb lang='pl'>
  <p>
  The printf method takes a format string as the first parameter.
  This string is printed but following parameters replace the % placeholders.
  </p>
  <p>%d is used for decimal numbers.
  </p>
  <table>
  <tr>
   <td class='imper'>Format</td>
   <td class='imper' style="width:6em">Code</td>
   <td class='imper'>Meaning</td></tr>
  <tr><td>Simple</td>
   <td><code>%d</code></td><td>A simple decimal number</td></tr>
  <tr><td>Right aligned</td>
   <td><code>%5d</code></td><td>Print right aligned in 5 characters.
        Fill any unused characters with spaces.</td></tr>
  <tr><td>Leading zeroes</td>
   <td><code>%05d</code></td><td>Print right aligned in 5 characters.
        Fill any unused characters with zero.</td></tr>
  <tr><td>Hexadecimal</td>
   <td><code>%x</code></td><td>Print as a hexadecimal (base 16) number.
        </td></tr>
  <tr><td>With commas</td>
   <td><code>%,d</code></td><td>Use , to separate thousands.
        </td></tr>
  </table>
  </blurb>
  <blurb lang="cs">
  <p>
  The <code>Write</code> method takes a format string as the first parameter.
  This string is printed but following parameters replace the {} placeholders.
  </p>
  <table style='clear:both'><tr>
   <td class='imper'>Format</td>
   <td  class='imper' style="width:6em">Code</td>
   <td class='imper'>Meaning</td>
  </tr><tr>
   <td>Simple</td>
   <td><code>{0}</code></td>
   <td>Simple conversion to string</td>
  </tr><tr>
   <td>Right aligned</td>
   <td><code>{0,12}</code></td>
   <td>Print right aligned in 12 characters. Fill any unused characters with spaces.</td>
  </tr><tr>
   <td>Leading zeroes</td>
   <td><code>{0:00000}</code></td>
   <td>Print right aligned in 5 characters. Fill any unused characters with zero.</td>
  </tr> <tr>
   <td>Hexadecimal</td>
   <td><code>%x</code></td>
   <td>Print as a hexadecimal (base 16) number.</td>
  </tr> <tr>
   <td>With commas</td>
   <td><code>{0,12:n0}</code></td>
   <td>Use , to separate thousands
    The whole string takes 12 characters, <code>:n0</code> means number format with 0 decimal places.
   </td></tr>
  </table>
  </blurb>
<prog lang="cs"><![CDATA[
using System;
public class Demo{
  public static void Main(string[] argv)
  {
    Console.Write("The answer:{0}\n", 42);
    Console.Write("The answer:{0,12}\n", 42);
    Console.Write("The answer:{0:00000}\n", 42);
    Console.Write("The answer:{0:x}\n", 42);
    Console.Write("The answer:{0,12:n0}\n", 42000000);
  }
}
]]></prog>
<prog lang="cpp"><![CDATA[
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
  cout << "The answer:" << " 42" << endl;
  return 0;
}
]]></prog>
<prog lang="pl"><![CDATA[
  printf "The answer:%d\n", 42;
  printf "The answer:%12d\n", 42;
  printf "The answer:%05d\n", 42;
  printf "The answer:%x\n", 42;
  printf "The answer:%,d\n", 42000000;
]]></prog>

<prog lang="java">
public class Demo{
  public static void main(String argv[])
  {
    System.out.printf("The answer:%d\n", 42);
    System.out.printf("The answer:%12d\n", 42);
    System.out.printf("The answer:%05d\n", 42);
    System.out.printf("The answer:%x\n", 42);
    System.out.printf("The answer:%,d\n", 42000000);
  }
}
</prog>

 </question>
</tutorial>

