“Nunca he encontrado una persona tan ignorante que no pueda aprender algo de ella.”
Mostrando entradas con la etiqueta java. Mostrar todas las entradas
Mostrando entradas con la etiqueta java. Mostrar todas las entradas

lunes, 15 de mayo de 2017

calendario java

Haz un calendario que te liste los días del año según el día que empezó ese año, según si es bisiesto o no, y teniendo en cuenta de que cada semana se salta de línea.



import java.util.*;
public class HelloWorld{

     public static void main(String []args){
       Scanner anio = new Scanner(System.in);
       int anno;
Scanner dio = new Scanner(System.in);
int dia;
       Scanner dias = new Scanner(System.in);
       String seman;
   
        System.out.println ("Que anno buscas?");
        anno = anio.nextInt();
        System.out.println ("Si lunes fuese -1, martes 0, miercoles 1 y etc, que dia empezo el anno?");
       dia = dio.nextInt();


System.out.println("Que dia comenzo ese anno?");
        seman = dias.nextLine();
            if (seman.equals("lunes")){
                int seman2 = -1;
               
            }else if (seman.equals("martes")){
                int seman2 = 0;
                System.out.print ("   ");
            }else if (seman.equals("miercoles")){
                int seman2 = 1;
                 System.out.print ("      ");
            }else if (seman.equals("jueves")){
                int seman2 = 2;
                 System.out.print ("         ");
            }else if (seman.equals("viernes")){
                int seman2 = 3;
                System.out.print ("            ");
            }else if (seman.equals("sabado")){
                int seman2 = 4;
                System.out.print ("               ");
            }else if (seman.equals("domingo")){
                int seman2 = 5;
                System.out.print ("                  ");
            }
       
       
         if (anno % 4 == 0 && anno % 400 == 0){
                for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=29; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 29 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 29 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 29 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 29 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 29 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
               
               
            }else if (anno % 4 == 0 && anno % 100 != 0){
                for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=29; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 29 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 29 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 29 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 29 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 29 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 29 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
               
               
            }else if (anno % 4 == 0 && anno % 400 != 0){
                for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=28; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 28 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 28 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 28 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 28 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 28 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                }else{
                 for (int i=1; i<=31; i++){
                    int mes = i + dia;
                    if (mes%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
                for (int i=1; i<=28; i++){
                    int mes2 = 31 + i + dia;
                    if (mes2%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes3 = 28 + 31 + i + dia;
                    if (mes3%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes4 = 28 + 31 + 31 + i + dia;
                    if (mes4%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes5 = 28 + 31 + 31 + i + dia + 30;
                    if (mes5%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes6 = 28 + 31 + 31 + i + dia + 30 + 31;
                    if (mes6%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes7 = 28 + 31 + 31 + i + dia + 30 + 31 + 30;
                    if (mes7%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes8 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31;
                    if (mes8%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes9 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31;
                    if (mes9%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes10 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30;
                    if (mes10%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=30; i++){
                    int mes11 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31;
                    if (mes11%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }for (int i=1; i<=31; i++){
                    int mes12 = 28 + 31 + 31 + i + dia + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
                    if (mes12%7 == 0){
                    System.out.println ("");
                    }
                   
                    if (i<10){
                        System.out.print (" 0" +i);
                    }else if (i >= 10 && i <= 31){
                        System.out.print (" " +i);  
               
                    }
                }
               
            }
         }
     }

Programa de java que te permite saber si una palabra comienza por mayúscula

ESTA LÍNEA DE CÓDIGOS PERMITE SABER SI UNA LETRA ES MAYÚSCULA O NO


import java.util.*;
import java.io.*;
public class HelloWorld{

     public static void main(String []args) throws IOException{
       Scanner car = new Scanner(System.in);
       char letra1;
     
     
        System.out.println("Dime una letra:");
        letra1 = (char)System.in.read();
     
        if (Character.isUpperCase(letra1)) {
            System.out.println ("Es una letra mayuscula.");
        }else{
            System.out.println ("No es una letra mayuscula.");
        }
     }
}

ESTA LÍNEA DE CÓDIGOS PERMITE SABER SI LA PALABRA QUE METEMOS COMIENZA POR MAYUSCULA

import java.util.*;
import java.io.*;
public class HelloWorld{

     public static void main(String []args) throws IOException{
       Scanner car = new Scanner(System.in);
      String palabra;
      System.out.println("Dime una palabra:");
      palabra = car.nextLine();
      char letra = palabra.charAt(0);
      if (Character.isUpperCase(letra)){
          System.out.println ("La palabra " +palabra +" empieza por mayuscula.");
         
      }else{
          System.out.println ("La palabra " +palabra +" no empieza por mayuscula.");
      }
     
     }
}

Programa de java que te permite contar las cifras de un numero

import java.util.*;

public class HelloWorld{

     public static void main(String []args){
     Scanner num = new Scanner(System.in);
     int numero1;
    int numero2;
        System.out.println("Dime un numero: ");
        numero1 = num.nextInt();
        numero2 = numero1;
        int cifrasnum = 0;
        while (numero2!=0){
          numero2 = numero2 / 10;
          cifrasnum++;
         
        }
            System.out.println ("El " +numero1 +" tiene " +cifrasnum +" cifras");
       
       
       
     }
}

Programa de java que te permite saber si un numero es par y sus divisores

import java.util.*;

public class HelloWorld{

     public static void main(String []args){
     Scanner num = new Scanner(System.in);
     int numero1;
        
        System.out.println("Dime un numero: ");
        numero1 = num.nextInt();
        if (numero1 % 2 == 0){
            System.out.print("Este numero es par, y sus divisores son: ");
           
            for (int i=1; i<=numero1; i++){
                if (numero1 % i == 0){
                    System.out.print(" " +i);
                     
                }
            }
        }else{
          System.out.print("Este numero es impar, y sus divisores son: ");
            for (int i=1; i<=numero1; i++){
                if (numero1 % i == 0){
                    System.out.print(" " +i);
                    
                }   
              
            }
        }
         System.out.println(" ");
    }
}