domingo, 29 de mayo de 2011

EJERCICIO CON VECTORES

package ejercicio2405arreglos;

/**
 *
 * @author MIC-03package
 */
import javax.swing.JOptionPane;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int pares[]={2, 4, 6, 8, 10};
        int impares[]={1, 3, 5, 7, 9};

        mostrarVector(pares);
        JOptionPane.showMessageDialog(null, "MEDIA="+media(pares));

        mostrarVector(impares);
        JOptionPane.showMessageDialog(null,"MEDIA="+media(impares));
    }
    static void mostrarVector(int datos[]){
        int i;
        for (i=0; i<datos.length; i++)
            JOptionPane.showMessageDialog(null,datos[i]);
    }
    static float media(int datos[]){
        int i;
        int n=datos.length;
        int suma=0;

        for(i=0; i<n; i++)
            suma=suma+datos[i];
        return suma/n;
    }

}

miércoles, 25 de mayo de 2011

Ingresar monto,sueldo y estado civil, si es soltero recibira 5% de aumento, casado sera 12% de aumento, mostrar aumento y neto

import javax.swing.JOptionPane;
public class ejerc05 {
public static void main(String[] args) {
    String nombre=JOptionPane.showInputDialog("ingrese nombre");
    String entrada=JOptionPane.showInputDialog("ingrese sueldo");
    int sueldo=Integer.parseInt(entrada);
    entrada=JOptionPane.showInputDialog("ingrese estado:1-soltero/ 2-casado");
    double ecivil=Double.parseDouble(entrada);
     int desc,aum,neto;
     switch(sueldo)
     {
         case 1:
             JOptionPane.showMessageDialog(null,"ingrese nombre"+1);
           
            
             break;
         case 2:
             JOptionPane.showMessageDialog(null, "ingrese ecivil"+(1-2));
            
             break;
         case 3:
             JOptionPane.showMessageDialog(null, "ingrese neto");break;
     }
   }
}

Ingresar monto de consumo y la zona (A,B,C)

import javax.swing.JOptionPane;
public class ejerc04 {
public static void main(String[] args) {

 String entrada=JOptionPane.showInputDialog("Iingresar monto del consumo:");
        double Numero1=Double.parseDouble(entrada);
        entrada=JOptionPane.showInputDialog("ingresar la zona: 1-A, 2-B, 3-C");
        int monto=Integer.parseInt(entrada);
        switch (monto){

      
      case 1: JOptionPane.showMessageDialog(null,"Monto: "+(Numero1+(Numero1*0.03))); break;
        case 2: JOptionPane.showMessageDialog(null,"Monto: "+(Numero1+(Numero1*0.08))); break;
        case 3: JOptionPane.showMessageDialog(null,"Monto: "+(Numero1+(Numero1*0.15))); break;
        default: JOptionPane.showMessageDialog(null, "No Selecciones (1-3)"); break;
        }
    }
}

ingresar los signos del zodiaco (1-12) y empiece por areas.

import javax.swing.JOptionPane;
public class ejerc03 {
public static void main(String[] args) {
String entrada =JOptionPane.showInputDialog("Ingresar los signos del zodiaco (1-12)");
    int zodiaco=Integer.parseInt(entrada);
  switch(zodiaco)
  {
      case 1:JOptionPane.showMessageDialog(null, "Aries");break;
      case 2:JOptionPane.showMessageDialog(null,"Tauro");break;
      case 3:JOptionPane.showMessageDialog(null,"Geminis");break;
      case 4:JOptionPane.showMessageDialog(null,"Cancer");break;
      case 5:JOptionPane.showMessageDialog(null,"Leo");break;
      case 6:JOptionPane.showMessageDialog(null,"Virgo");break;
      case 7:JOptionPane.showMessageDialog(null,"Libra");break;
      case 8:JOptionPane.showMessageDialog(null,"Escorpio");break;
      case 9:JOptionPane.showMessageDialog(null,"Sagitario");break;
      case 10:JOptionPane.showMessageDialog(null,"Capricornio");break;
      case 11:JOptionPane.showMessageDialog(null,"Acuario");break;
      case 12:JOptionPane.showMessageDialog(null,"Pisis");break;
      default:JOptionPane.showMessageDialog(null,"signo no valido" );break;
  }
 }
}

Sentencias Switch. ingresar dos numeros y un signo, suma,resta,multiplicacion,division

import javax.swing.JOptionPane;
public class ejerc02 {
    public static void main(String[] args) {
    String entrada=JOptionPane.showInputDialog("Ingresar numero1");
    double num1=Double.parseDouble(entrada);
    entrada=JOptionPane.showInputDialog("ingresar numero2");
    double num2=Double.parseDouble(entrada);
    String signo=JOptionPane.showInputDialog("Ingresa la poperacion:1-suma/ 2-resta/ 3-multiplicacion/ 4-division");
    int operacion=Integer.parseInt(signo);
    switch(operacion)
     {
    case 1:JOptionPane.showMessageDialog(null,"suma"+(num1+num2));break;
    case 2:JOptionPane.showInputDialog("resta" +(num1-num2));break;
    case 3:JOptionPane.showInputDialog("multiplicacion" +(num1*num2));break;
    case 4:JOptionPane.showInputDialog("division" +(num1/num2));break;

    default:JOptionPane.showInternalMessageDialog(null,"operacion no valida");
     }
   }
}

Sentencia Switch , Meses del año

import javax.swing.JOptionPane;
public class ejerc01 {
public static void main(String args[]){
String entrada=JOptionPane.showInputDialog("Ingrese numero de meses(1-12)");
int meses=Integer.parseInt(entrada);

  switch(meses)
  {

   case 1:JOptionPane.showMessageDialog(null,"Enero:"); break;
   case 2:JOptionPane.showMessageDialog(null,"Febrero:"); break;
   case 3:JOptionPane.showMessageDialog(null,"marzo:"); break;
   case 4:JOptionPane.showMessageDialog(null,"Abril:"); break;
   case 5:JOptionPane.showMessageDialog(null,"Mayo:"); break;
   case 6:JOptionPane.showMessageDialog(null,"junio:"); break;
   case 7:JOptionPane.showMessageDialog(null,"julio:"); break;
   case 8: JOptionPane.showMessageDialog(null,"Agosto:"); break;
   case 9:JOptionPane.showMessageDialog(null,"Setiembre:"); break;
   case 10:JOptionPane.showMessageDialog(null,"Octubre:"); break;
   case 11:JOptionPane.showMessageDialog(null,"Novienbre:"); break;
   case 12:JOptionPane.showMessageDialog(null,"Dicienbre:"); break;

   default: JOptionPane.showMessageDialog (null,"No es valido:");break;
      }
    }
}

domingo, 15 de mayo de 2011

MOSTAR EL PROMEDIO DE LAS CINCO NOTAS , DETERMINANDO LA MAYOR Y MENOR DE ELLAS

import javax.swing.JOptionPane;
public class ejemp07_notas{
public static void main(String args[]){
    int nota1, nota2, nota3, nota4, nota5, menor,mayor, prom;
nota1 =Integer.parseInt(JOptionPane.showInputDialog("Ingrese Nota 1 :"));
nota2 =Integer.parseInt(JOptionPane.showInputDialog("Ingrese Nota 2 :"));
nota3 =Integer.parseInt(JOptionPane.showInputDialog("Ingrese Nota 3 :"));
nota4 =Integer.parseInt(JOptionPane.showInputDialog("Ingrese Nota 4 :"));
nota5 =Integer.parseInt(JOptionPane.showInputDialog("Ingrese Nota 5 :"));
menor=nota1;
mayor=nota2;
prom = 0;
 if(nota2<menor){
 menor=nota2;
    }
 else
    if (nota2>mayor){
        mayor=nota2;
    }
 if(nota3<menor){
     menor=nota3;
    }
 else
     if (nota3>mayor){
         mayor=nota3;
     }
 if(nota4<menor){
 menor=nota4;
    }
   if (nota4>mayor){
       mayor=nota4;
   }
 if(nota5<menor){
     menor=nota5;
    }
 else
     if (nota5> mayor){
         mayor=nota5;
     }


  prom = (nota1 + nota2 + nota3 + nota4 + nota5)/5;

JOptionPane.showMessageDialog (null, "La nota menor es : " + menor);
JOptionPane.showMessageDialog(null, "la nota mayor es: " + mayor);
JOptionPane.showMessageDialog(null,"el promedio es: " + prom);

   }
  }

INGRESAR EL FACTORIAL DE UN NÙMERO

import javax.swing.JOptionPane;
public class ejemp06_fact{
 public static void main (String args[]){
   int i = 1, acu = 1, num = 0, seguir = 0;
   String Numero;
 while(seguir == 0){//inicio while validar numero positivo
 Numero = JOptionPane.showInputDialog("Que numero factorial desea calcular? ");
    num = Integer.parseInt( Numero );

 if(num <= 0){
JOptionPane.showMessageDialog(null,"Error,Ingrese un numero positivo",
"Error", JOptionPane.PLAIN_MESSAGE);
 }
else{
seguir = 1;
    }
}//fin while validar numero positivo
while(i <= num){
acu = acu * i;
i++;
}

 JOptionPane.showMessageDialog(null, "" + num + "!  = " + acu, "Resultado",
 JOptionPane.PLAIN_MESSAGE);

         System.exit(0);
    }
 }

TABLA DE MULTIPLICACION CON FOR

import javax.swing.JOptionPane;
public class ejemp05_for{
    public static void main(String args[]){
    int i;
    







i = Integer.parseInt(JOptionPane.showInputDialog("¿Cual tabla de multiplicar del 1 al 12 quieres que te imprima?" ));
    switch (i) {
 case 1:
for (i = 0; i < 12 ; i++){
System.out.printf("\n1 x "+ i +" = "+(i*1));
}
break;
case 2:
for (i = 0; i < 12 ; i++){
System.out.printf("\n2 x "+ i +" = "+(i*2));
}
break;
case 3:
for (i = 0; i < 12 ; i++){
System.out.printf("\n3 x "+ i +" = "+(i*3));
}
break;
  case 4:
for (i = 0; i < 12 ; i++){
System.out.printf("\n4 x "+ i +" = "+(i*4));
}
break;
 case 5:
for (i = 0; i < 12 ; i++){
System.out.printf("\n5 x "+ i +" = "+(i*5));
}
break;
  case 6:
for (i = 0; i < 12 ; i++){
System.out.printf("\n6 x "+ i +" = "+(i*6));
}
break;
  case 7:
for (i = 0; i < 12 ; i++){
System.out.printf("\n7 x "+ i +" = "+(i*7));
}
break;
  case 8:
for (i = 0; i < 12 ; i++){
System.out.printf("\n8 x "+ i +" = "+(i*8));
}
break;
  case 9:
for (i = 0; i < 12 ; i++){
System.out.printf("\n9 x "+ i +" = "+(i*9));
}
break;
   case 10:
for (i = 0; i < 12 ; i++){
System.out.printf("\n10 x "+ i +" = "+(i*10));
}
break;
   case 11:
 for (i =0; i < 12 ; i++){
     System.out.printf("\n11 x "+ i +" = "+(i*11));
       }
     break;
   case 12:
  for (i =0; i < 12 ; i++){
     System.out.printf("\n12 x "+ i +" = "+(i*12)); 
        }
  break;
        default:
            JOptionPane.showMessageDialog(null, "La opcion no existe:");
break;
   }
  }
}

INGRESAR LA CANTIDAD DE NUMEROS POSITIVOS Y NEGATIVOS UTILIZANDO WHILE

import javax.swing.JOptionPane;
public class ejemp04_while{
    public static void main(String args[]){
     String entrada=JOptionPane.showInputDialog("ingrese cantidad de numeros negativos");
     int neg= Integer.parseInt(entrada);
     String cant=JOptionPane.showInputDialog("ingrese cantidad de numeros positivos");
     int pos= Integer.parseInt(cant);
     int n;
     int i=1;
     while(i<=pos ){
     String nume  = JOptionPane.showInputDialog("ingrese el num"+i+":");
       int num =Integer.parseInt(nume);
       if (num > 0){
          
           pos=pos+1;
         }
            else

           if (num < 0){
              
               neg=neg+1;
               }
            else
            {
            JOptionPane.showMessageDialog (null,"el numero ingresado es cero");
             }
            i=i+1;
             {
           JOptionPane.showMessageDialog (null,"total de numeros negativos:" + neg);
           JOptionPane.showMessageDialog (null, "total de numeros positivos:" + pos);
              }

           }
       }
     }

TABLA DE MULTIPLICACION CON WHILE

import javax.swing.JOptionPane;
public class ejemp03_while{
    public static void main(String args[]){
        String entrada=JOptionPane.showInputDialog("ingrese numero");
        int num=Integer.parseInt(entrada);
        int i;
        i=0;
        while (i<=12){
            JOptionPane.showMessageDialog(null,num+"*"+i+"="+(num*i));
            i=i+1;
        }
      }
    }




mostrar la cantidad de numeros determinados

import javax.swing.JOptionPane;
public class ejemp02{
    public static void main(String args[]){
        String entrada= JOptionPane.showInputDialog("ingrese numero");
        int mun=Integer.parseInt(entrada);
        int i;
        i=1;
        while(i<=mun)
        {
            JOptionPane.showMessageDialog(null,"el num es"+i);
            i=i+1;
        }

    }
}

convertir soles a dolares y euros

import javax.swing.JOptionPane;
public class dolares_euros{
public static void main (String args[]){
    String cant = JOptionPane.showInputDialog("ingrese cantidad de soles ");
    double soles= Double.parseDouble(cant);

    double dolares = soles/2.80;
    double euros = soles/3.50;
    JOptionPane.showMessageDialog(null,"la cantidad de dolares es: "+ dolares);
    JOptionPane.showMessageDialog(null,"la cantidad de euros es: "+ euros);
    }
  }

MOSTRAR LOS DIEZ PRIMEROS NÙMEROS NATURALES

import javax.swing.JOptionPane;
public class ejemp01{
    public static void main (String args[]){
        String hola=JOptionPane.showInputDialog("mostrar diez primeros numeros");
        Double mun= Double.parseDouble(hola);
        int i;
        i=1;
        while(i<=10){
            {
            JOptionPane.showMessageDialog(null,"el  mun es" +i);
            i=i+1;
            }
        }
    }
}