title: How can I format a given date in Java using switch case?
body: <p>I need to format a date (month, year), but I can't do it correctly.</p>
  <p>The problem is:
  Given the following data<br />
  Year: 2016<br />
  Month: 12<br />
  Date: 31<br />
  Next N days: 5</p>
  <p>Produce the following output:<br />
  &quot;December has as many as 31 days&quot;<br />
  &quot;Today date: December 31st 2016&quot;<br />
  &quot;Tomorrow's date: January 1, 2017&quot;<br />
  &quot;5 days to go: January 5, 2017&quot;.</p>
  <p>How can I format those dates by using a switch statement (as requested by my teacher)?</p>
  <pre><code>import java.util.Scanner;
  
  import javax.lang.model.util.ElementScanner6;
  
  public class TugasNo4 {
  public static void main(String[] args) {
      int years, month, date, nday;
      String monthname = &quot;&quot;;
  
      Scanner input = new Scanner(System.in);
  
      System.out.print(&quot;Tahun: &quot;);
      years = input.nextInt();
  
      System.out.print(&quot;Bulan: &quot;);
      month = input.nextInt();
  
      System.out.print(&quot;Tanggal: &quot;);
      date = input.nextInt();
      if(date &lt;= 0){
          System.out.println(&quot;Anda memasukkan tanggal yang salah!&quot;);
          input.close();
      }
  
      System.out.print(&quot;N hari kedepan: &quot;);
      nday = input.nextInt();        
  
      switch(month){
          case 1:
          monthname = &quot;Januari&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 31 hari&quot;);            
          break;
          case 3:
          monthname = &quot;Maret&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 31 hari&quot;);            
          break;
          case 5:
          monthname = &quot;May&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 31 hari&quot;);            
          break;
          case 7:
          monthname = &quot;July&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 31 hari&quot;);            
          break;
          case 8:
          monthname = &quot;Agustus&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 31 hari&quot;);
          break;
          case 10:
          monthname = &quot;Oktober&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 31 hari&quot;);
          break;
          case 12:
          monthname = &quot;Desember&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 31 hari&quot;);
          break;
          case 4:
          monthname = &quot;April&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 30 hari&quot;);
          break;
          case 6:
          monthname = &quot;Juni&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 30 hari&quot;);
          break;
          case 9:
          monthname = &quot;September&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 30 hari&quot;);
          break;
          case 11:
          monthname = &quot;November&quot;;
          System.out.println(monthname+&quot; memiliki hari sebanyak 30 hari&quot;);
          break;
          case 2:
          monthname = &quot;Februari&quot;;
          if((years % 4 == 0) &amp;&amp; !(years % 100 == 0))
          System.out.println(monthname+&quot; memiliki hari sebanyak 29 hari&quot;);     
          else 
          System.out.println(monthname+&quot; memiliki hari sebanyak 28 hari&quot;);       
          break;            
          default:
          System.out.println(&quot;Anda memasukkkan bulan yang salah&quot;);
          break;
      }
      System.out.println(&quot;Hari ini tanggal: &quot;+date+&quot; &quot;+monthname+&quot; &quot;+years);
  
      int datebesok = date + 1;
      System.out.println(&quot;Besok tanggal &quot;+datebesok+&quot; &quot;+monthname+&quot; &quot;+years);
  
      int datenday = date + nday;
      if((month == 2) &amp;&amp; (datenday &lt;= 28) &amp;&amp; (datenday &lt;= 29)){
          System.out.println(nday+&quot; hari lagi tanggal: &quot;+datenday+&quot; &quot;+monthname+&quot; &quot;+years);
      }
    }
  }
  </code></pre>