Entradas

Mostrando las entradas de mayo, 2012

Imagen de fondo de fondo con JLabel

     style="display:inline-block;width:728px;height:90px"      data-ad-client="ca-pub-5126364088863607"      data-ad-slot="9520827110"> CARGAR UNA  IMAGEN DE FONDO EN SWING CON JLABEL import javax.swing.*; public class hola_mundo { private JFrame programa=new JFrame("mi programa"); private JLabel imagen; private ImageIcon icono; private JButton boton; public hola_mundo() { boton=new JButton("soy un boton");  programa=new JFrame("mi programa"); imagen=new JLabel(); icono=new ImageIcon("imagen.jpeg");// direccion de la imagen (no tiene // porque se encuentra en la misma carpeta)

Vuelto de una compra

Imagen
MOSTRAR EL VUELTO DE UNA COMPRA  Codigo Fuente

Preguntas tablas de multiplicar

Imagen
PIDA UN NUMERO Y GENERE PREGUNTAS SOBRE SU TABLA DE MULTIPLICAR SIN REPETIR LA MISMA PREGUNTA

Manejo Matrices

     style="display:inline-block;width:728px;height:90px"      data-ad-client="ca-pub-5126364088863607"      data-ad-slot="9520827110"> CREAR DOS MATRICES DE 5X5 Y LLENARLAS ALEATOREAMENTE, LUEGO RECORRER AMBOS ARREGLOS VERIFICANDO SI UN NUMERO DE REPITE EN AMBOS AREGLOS, PARA POSTERIORMENTE SER MOSTRADOS import java.util.Random; public class Ejemplo17 {     public static void main(String[]args){         int N = 5;         int arreglo1 [][] = new int[N][N];         int arreglo2 [][] = new int[N][N];         int numerosRepetido [] = new int[N*N];         int contador = 0;      

Congruencia de zeller

MOSTRAR EL DIA DE LA SEMANA DE LA FECHA QUE SE INGRESA (LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO, DOMINGO) import java.util.Scanner; public class Ejemplo14 {     public static void main(String[]args){         String dias []= { " Domingo ", " Lunes "," Martes "," Miercoles "," Jueves "," Viernes "," Sabado " };         Scanner leer = new Scanner (System.in);               System.out.print( "Ingrese dia: " );         int dia = leer.nextInt();         System.out.print( "Ingrese mes: " );         int mes = leer.nextInt();         System.out.print( "Ingrese anio: " );         int anio = leer.nextInt();         //congruencia de Zeller         if ((dia < 32)&&(mes < 13)&&(anio < 10000)){ //si la fecha es correcta               int a = (14 - mes) / 12;              int y = anio - a;              int m = mes + 12 * a - 2;      

Manejo de matrices

     style="display:inline-block;width:728px;height:90px"      data-ad-client="ca-pub-5126364088863607"      data-ad-slot="9520827110"> CREAR UNA MATRIZ DE 5X5 Y LLENARLO CON NUMEROS ALEATORIOS, LUEGO HACER LA SUMA DE LOS NUMEROS QUE SE ENCUANTRES EN SU DIAGONAL, SUMAR LOS NUMEROS QUE SE ENCUENTREN BAJO LA DIAGONAL, SUMAR LOS NUMEROS SOBRE LA DIAGONAL, MOSTAR EL MENOR NUMERO DE LA MATRIZ Y EL MAYOR NUMERO. public class Ejemplo13 {     public static void main (String[] args)     {         System.out.print("Matriz de 5 filas por 5 columnas de contenido aleatorio:\n");               int N=5,i,j;         int diag=0;         int diagb=0;         int diags=0;         int matriz[][]=new int[N][N];         String menor=new String();         String mayor=new String();         System.out.print("Columna 0  1  2  3  4\n");         for (i=0;i<N;i++)         {             System.out.print("Fila"+i+" &q

Oracion simetrica

VERIFICAR SI UNA ORACION ES SIMETRICA, ES DECIR, QUE SE PUEDA LEER DE IGUAL FORMA POR AMBOS LADOS. import java.util.*; public class Ejemplo11{     public static void main(String[] args) {        Scanner leer = new Scanner(System.in);        System.out.println("Ingrese frase :");        String frase = leer.nextLine();        int largoFrase = frase.length()-1;        Boolean simetrica = true;        for (int contador = 0;contador < largoFrase; contador++){             char tex1 = frase.charAt(contador);//avanza letra por letra de izquierda a derecha             char tex2 = frase.charAt(largoFrase);//avanza letra por letra en sentido contrario             if(tex1!=tex2){                 simetrica = false; //si no es identica es false             }                   largoFrase--;         }        if(simetrica == false){             System.out.println("La frase ingresada  : no es simétrica");         }        if(simetrica == true){          

Escribir y leer un archivo

ESCRIBIR EN UN ARCHIVO ORACIONES Y DESPUES LEER LAS ORACIONES INGRESADAS import java.io.*; import java.util.Scanner; public class Ejemplo10{     public static void main(String[] args) {         // Validamos si existe el fichero                   Scanner leer = new Scanner(System.in);         String sFichero = "fichero.txt";//se le asifna un nombre al fichero         File fichero = new File(sFichero);//se crea un fichero         if (fichero.exists())//si el fichero esta creado             System.out.println("El fichero " + sFichero //imprimir el fichero ya existe             + " ya existe");         else {

Porcentaje de veces que se repite un numero

MOSTRAR EL PORCENTAJE DE VECES QUE SE REPITE LOS NUMEROS DE 1 AL 6 10000 VECES public class Ejemplo9 {     public static void main(String[]args){     int Random;     int uno=0, dos=0, tres=0, cuatro=0, cinco=0, seis=0;     double puno=0, pdos=0, ptres=0, pcuatro=0, pcinco=0, pseis=0;     for(int i = 1; i <= 10000; i++)     {         Random = (int)(Math.random()*6+1);//GENERA NUMEROS ALEATORIOS DESDE 1 A 6             if(Random == 1 )uno++;//SI EL NUMERO RANDOM ES 1 ENTONCES AUNMENTA CONTADOR UNO             else if(Random == 2) dos++;             else if(Random == 3)tres++;             else if(Random == 4)cuatro++;             else if(Random == 5)cinco++;             else if(Random == 6)seis++;     }

Sumar rango

SUMAR LOS NUMEROS QUE SE ENCUENTREN EN UN RAGO import java.util.Scanner; public class Ejemplo8 {    public static void main(String [] args){         Scanner leer = new Scanner (System.in);         int suma = 0;         int i;         System.out.print("Desde: ");         int BAJO = leer.nextInt();//SE LE PUDE UN TOPE MINIMO         System.out.print("Hasta: ");         int ALTO = leer.nextInt();//SE LE PIDE UN TOPE MAXIMO               for(i = BAJO+1; i < ALTO; i++)         {             suma += i;//SE SUMAN LOS NUMEROS QUE ESTAN ENTRE EL TOPE MINIMO Y EL TOPE MAXIMO         }         System.out.println("Suma: "+suma);//SE IMPRIME LA SUMA           if(suma==0)System.out.println("No hay enteros entre ellos");//SE EL MIN ES 23 Y EL MAX ES 24 NO                                                                     //EXISTIRIA SUMA POT LO CUAL NO HAY                                                                     //NUMEROS

Mostar articulo sustantivo y verbo

MOSTRAR  UNA ORACION DONDE SE CONCATENE UN ARTICULO SU RESPECTIVO SUSTANTIVO Y UN VERBO TODO ALEATOREAMENTE import java.util.Random; public class Ejemplo6 {     public static void main(String[]args){         String articulo[] = { "EL ","UN ","LA ","UNA " };         String sustantivo_femenino[]={ " ABUELA "," TRAIDORA "," PANTERA "," SILLA "," FLOR "," MUNECA " };         String sustantivo_masculino[]={ " PADRE "," ABUELO "," LEON "," JARRON "," PATIO "," MUNECO " };         String verbo[]={ "AMENAZA","RIE","CORRE","PERDONA","JUEGA","CANTA","SALPICA","GIRA","CORRE","MIRA" };    

Ecuacion de segundo grado

Decimal a romano

Imagen

Romanos a decimal

Imagen
     style="display:inline-block;width:728px;height:90px"      data-ad-client="ca-pub-5126364088863607"      data-ad-slot="9520827110">

Convertir decimal a binario, octal y hexadecima

     style="display:inline-block;width:728px;height:90px"      data-ad-client="ca-pub-5126364088863607"      data-ad-slot="9520827110"> Bienvenid@ lector/a, en esta nueva entrada que será algo pequeña, mostrare el procedimiento de c onversión de números a base binaria, octal y decimal . Este ejemplo es en java pero puedes encontrar un ejemplo actualizado bajo la tecnología c# visitando el siguiente enlace Convertir decimal a binario, octal y hexadecimal c#. import java.util.Scanner; public class Ejemplo1 {     public static void main(String[]args){         Scanner leer = new Scanner(System.in);         System.out.print("Ingrese una cifra: ");         int cifra = leer.nextInt();         System.out.print("\nbinario:\t");         binario(cifra);         System.out.print("\noctal:\t\t");         octal(cifra);         System.out.print("\nHexadecimal:\t");         hexadecimal(cifra);         }