<tutorial title="Formatting Strings and Numbers" ht='1'>
 <blurb>
  We can format output involving fixed and variable components.
  Usually we align strings to the left and numebrs to the right.
 </blurb>
 <blurb lang="java">
 </blurb>
 <question className="Demo" title="">
  <blurb lang='java'>
  <p>
  In the <code>printf</code> a number of values may follow the format string.
  These values are used up by <code>%</code> placeholders in the format string.
  </p>
  <p>The format string is <pre>"Country: %-18s GDP: %,20d\n"</pre>
  </p>
  <dl>
   <dt><code>%-18s</code></dt>
   <dd>the minus in <code>-18</code> means align left,
       the <code>18</code> means 18 characters
       are to be used, the <code>s</code> is for string.</dd>
   <dt><code>%,20d</code></dt>
   <dd>the comma means include , separator every three digits, the 20
       means use 20 characters and align right, d is for decimal.
   </dd>
   <dt><code>\n</code></dt><dd>This starts a new line.</dd>
  </dl>
  </blurb>
  <blurb lang="cs">
  <p>
  In the <code>Write</code> a number of values may follow the format string.
  These values are used up by <code>{0}, {1}</code> placeholders in the format string.
  </p>
  <p>The format string is <pre>"Country: {0:-18} GDP: {1,20:n0}\n"</pre>
  </p>
  <dl>
   <dt><code>{0:-18}</code></dt>
   <dd>the minus in <code>-18</code> means align left,
       the <code>18</code> means 18 characters
       are to be used.</dd>
   <dt><code>{1,20:n0}</code></dt>
   <dd>
       The 20 means use 20 characters and align right, d is for decimal,
       the <code>n0</code> means include , separator every three digits and
       give zero decimal places.
   </dd>
   <dt><code>\n</code></dt><dd>This starts a new line.</dd>
  </dl>
  </blurb>
  <shell lang="java" className="Demo"><![CDATA[
public class Demo{
QcQ
public static void main(String [] argv){
doLine("United Kingdom",1782000000000L);
doLine("Uganda",39390000000L);
}}
]]></shell>
<prog lang="java"><![CDATA[
static void doLine(String name, long gdp)
{
  System.out.printf("Country: %-18s GDP: %,20d\n",
          name, gdp);
}]]></prog>

  <shell lang="cs" className="Demo"><![CDATA[
using System;
public class Demo{
QcQ
public static void Main(string [] argv){
doLine("Uganda",39390000000L);
doLine("United Kingdom",1782000000000L);
}}
]]></shell>
<prog lang="cs"><![CDATA[
static void doLine(string name, long gdp)
{
  Console.Write("Country: {0,-18} GDP: {1,20:n0}\n",
          name, gdp);
}]]></prog>

 </question>

</tutorial>

