Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.time.LocalDate;
  3. import java.time.DayOfWeek;
  4.  
  5. public class calendario {
  6.     public static void main (String[] args){
  7.         int ano, mes;
  8.         Scanner leitor = new Scanner(System.in);
  9.         System.out.printf("Ano: ");
  10.         ano = leitor.nextInt();
  11.         System.out.printf("Mes: ");
  12.         mes = leitor.nextInt();
  13.        
  14.         System.out.println();
  15.        
  16.         System.out.println("Seg Ter Qua Qui Sex Sab Dom");
  17.         LocalDate data = LocalDate.of(ano, mes, 1);
  18.         DayOfWeek dia = data.getDayOfWeek();
  19.        
  20.         for (int i=1; i < dia.getValue(); i++){
  21.             System.out.printf("    ");
  22.         }
  23.        
  24.         while( data.getMonthValue() == mes){
  25.             System.out.printf("%d", data.getDayOfMonth());
  26.             if (data.getDayOfMonth() < 10){
  27.                 System.out.printf("   ");
  28.             }else{
  29.                 System.out.printf("  ");
  30.             }
  31.             dia = data.getDayOfWeek();
  32.             if (dia.getValue() == 7)
  33.                 System.out.println();
  34.             data = data.plusDays(1);
  35.         }
  36.         System.out.println();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement