Sunteți pe pagina 1din 32

UNIVERSIDAD REGIONAL AUTONOMA DE LOS

ANDES
UNIANDES-IBARRA
CARRERAR DE SISTEMAS
FACULTAD DE SISTEMAS MERCANTILES
NOMBRE: JEFFERSON BEDN

FECHA: 17/04/2016

ASIGNATURA: PROGRAMACION OB.

NIVEL: CUARTO

1. Que rellene un array con los 100 primeros nmeros enteros y los muestre en
pantalla en orden ascendente.
package pkg1.ascendente;
public class ascendente1 extends javax.swing.JFrame {
public ascendente1() {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {
String suma="";
int vector[]=new int [100];
for(int i=1;i<=100;i++){
vector[i-1]=i;
suma+=vector[i-1]+"; ";
if(i%10==0){
suma+="\n";
}}
rellenar.setText(suma+"");
}}

2. Que rellene un array con los 100 primeros nmeros enteros y los muestre en
pantalla en orden descendente.
package pkg1.descendente;
public class descendente1 extends javax.swing.JFrame {
public descendente1() {
initComponents();
}
private void botonrellenarActionPerformed(java.awt.event.ActionEvent evt) {
String suma ="";
int vector[]=new int [100];
int entero=101;

for(int i=1;i<=100;i++){
vector[i-1]=entero-i;
suma+=vector[i-1]+"; ";
if(i%10==0){
suma+="\n";
}
}
relleno.setText(suma);
} }

3. Que rellene un array con los nmeros primos comprendidos entre 1 y 100 y los
muestre en pantalla en orden ascendente.
package numros_primos;
public class ascendente extends javax.swing.JFrame {
public ascendente() {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {
String numero="";
int entero=100;
int a=1;
int b=2;
int c=2;
while (c<=entero){
if(b%c==0){
if(b==c){
numero+=b+" ";
a++;}
c=2;
b++;
}else
c++;}
relleno.setText(numero+" ");
}}

4.

Que rellene un array con los nmeros pares comprendidos entre 1 y 100 y los
muestre en pantalla en orden ascendente.

package pares;

public class ordenar extends javax.swing.JFrame {


public ordenar() {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {
String rellenar="";
int vector[]=new int [101];
for (int i=2;i<=100;i=i+2){
vector[i-1]=i;
rellenar+=vector[i-1]+"; ";
if(i%10==0){
rellenar+="\n";}}
RELLENO.setText(rellenar+" ");
}}

5.

Que rellene un array con los nmeros impares comprendidos entre 1 y 100 y los
muestre en pantalla en orden ascendente.

package impares;
public class ordenar extends javax.swing.JFrame {
public ordenar () {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {
String pares="";
int vector[]=new int [101];
for (int i=1;i<=100;i=i+2){
vector[i-1]=i;
pares+=vector[i-1]+" ";
if(i%10==0){
pares+="\n";}}
rellenar.setText(pares+" ");
}}

6.

Que lea 10 nmeros por teclado, los almacene en un array y muestre la suma,
resta, multiplicacin y divisin de todos.

package operaciones.pkg10;
public class operaciones extends javax.swing.JFrame {
public operaciones() {

initComponents();
}
private void boton_calcularActionPerformed(java.awt.event.ActionEvent evt) {
String relleno="";
int a= Integer.parseInt(uno.getText());
int b= Integer.parseInt(dos.getText());
int c= Integer.parseInt(tres.getText());
int d= Integer.parseInt(cuatro.getText());
int e= Integer.parseInt(cinco.getText());
int f= Integer.parseInt(seis.getText());
int g= Integer.parseInt(siete.getText());
int h= Integer.parseInt(ocho.getText());
int i= Integer.parseInt(nueve.getText());
int j= Integer.parseInt(diez.getText());
int suma= (a+b+c+d+e+f+g+h+i+j);
String ressum= Integer.toString(suma);
ressuma.setText(ressum);
int resta= (a-b-c-d-e-f-g-h-i-j);
String resres= Integer.toString(resta);
resresta.setText(resres);
double mul= (a*b*c*d*e*f*g*h*i*j);
String resmul= Double.toString(mul);
resmulti.setText(resmul);
double divicion= (a/b/c/d/e/f/g/h/i/j);
String resdiv= Double.toString(divicion);
resdivision.setText(resdiv);
relleno+=a+", "+b+", "+c+", "+d+", "+e+", "+f+", "+g+", "+h+", "+i+", "+j+" ";
llenado.setText(relleno);
}}

7.

Que lea 10 nmeros por teclado, los almacene en un array y los ordene de forma
ascendente.

package relleno.pkg10;
public class relleno1 extends javax.swing.JFrame {
public relleno1() {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {
String operaciones= "";
int vector[]=new int[10];
int aux;
vector[0]= Integer.parseInt(uno.getText());

vector[1]= Integer.parseInt(dos.getText());
vector[2]= Integer.parseInt(tres.getText());
vector[3]= Integer.parseInt(cuatro.getText());
vector[4]= Integer.parseInt(cinco.getText());
vector[5]= Integer.parseInt(seis.getText());
vector[6]= Integer.parseInt(siete.getText());
vector[7]= Integer.parseInt(ocho.getText());
vector[8]= Integer.parseInt(nueve.getText());
vector[9]= Integer.parseInt(dies.getText());
for(int i=0;i<10;i++) {
for(int j=i+1;j<10;j++) {
if(vector[j]<vector[i])
{
aux=vector[i];
vector[i]=vector[j];
vector[j]=aux;
}}
operaciones+= vector[i]+" ";}
for(int i=0;i<10;i++)
{
vectorlleno.setText(operaciones);
}}}

8.

Que lea 10 nmeros por teclado, 5 para un array y 5 para otro array distinto.
Mostrar los 10 nmeros en pantalla mediante un solo array.

package ejercicios.pkg10;
public class vectores extends javax.swing.JFrame {
public vectores() {
initComponents();
}
private void botongenrarActionPerformed(java.awt.event.ActionEvent evt) {
String vector="";
String vectorX = "";
String vectorZ = "";
int a = Integer.parseInt(uno.getText());
int b = Integer.parseInt(dos.getText());
int c = Integer.parseInt(tres.getText());
int d = Integer.parseInt(cuatro.getText());
int e = Integer.parseInt(cinco.getText());
int f= Integer.parseInt(seis.getText());
int g= Integer.parseInt(siete.getText());
int h= Integer.parseInt(ocho.getText());
int i= Integer.parseInt(nueve.getText());
int j= Integer.parseInt(diez.getText());

vectorX += a + ", " + b + ", " + c + ", " + d + ", " + e;


vectorA.setText(vectorX);
vectorZ += f+", "+g+", "+h+", "+i+", "+j+" ";
vectorB.setText(vectorZ);
vector+=a+", "+b+", "+c+", "+d+", "+e+", "+f+", "+g+", "+h+", "+i+", "+j+" ";
union.setText(vector);
}}}

9.

Que lea 5 nmeros por teclado, los copie a otro array multiplicados por 2 y
muestre el segundo array.

package ejercicios.pkg10;
public class dos extends javax.swing.JFrame {
public dos() {
initComponents();
}
private void botongenrarActionPerformed(java.awt.event.ActionEvent evt) {
String vectorX = "";
String vectorY = "";
int a = Integer.parseInt(uno.getText());
int b = Integer.parseInt(dos.getText());
int c = Integer.parseInt(tres.getText());
int d = Integer.parseInt(cuatro.getText());
int e = Integer.parseInt(cinco.getText());
vectorX += a + ", " + b + ", " + c + ", " + d + ", " + e;
vector.setText(vectorX);
vectorY += a * 2 + ", " + b * 2 + ", " + c * 2 + ", " + d * 2 + ", " + e * 2;
vector2.setText(vectorY);
}}}

10. Que lea 5 nmeros por teclado, los copie a otro array multiplicados por 2 y los
muestre todos ordenados usando un tercer array.
package ejercicios_6.pkg10;
public class ejercicio10 extends javax.swing.JFrame {
public ejercicio10() {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {

String vectorA = "";


String vectorB = "";
String vector= "";
int vec[]=new int[5];
int aux;
vec[0]= Integer.parseInt(uno.getText());
vec[1]= Integer.parseInt(dos.getText());
vec[2]= Integer.parseInt(tres.getText());
vec[3]= Integer.parseInt(cuatro.getText());
vec[4]= Integer.parseInt(cinco.getText());
for(int i=0;i<5;i++){
vectorA+= vec[i]+" ";
vectoringresado.setText(vectorA);
vectorB+= vec[i]*2+" ";
mutiplixacion.setText(vectorB);
}
for(int i=0;i<5;i++) {
for(int j=i+1;j<5;j++) {
if(vec[j]<vec[i]) {
aux=vec[i];
vec[i]=vec[j];
vec[j]=aux;
}}
vector+= vec[i]*2+" ";
}
for(int i=0;i<5;i++)
{
vectorordenado.setText(vector);
}}}

11. Que rellene un array con los 100 primeros nmeros pares y muestre su suma.
package ejercicio;
public class pares extends javax.swing.JFrame {
public pares() {
initComponents();
}
private void botongenrarActionPerformed(java.awt.event.ActionEvent evt) {
String vector ="";
int suma = 0;
int A [ ] = new int [101];
A[0] = 2;
for ( int i = 1; i <= 100 ; i++ ) {

A[ i ]=i*2;
suma=suma+A[ i ];
vector += A[ i ]+" ";
}
PARES.setText( vector );
SUMA.setText("LA SUMA DE LOS NUMEROS PARES ES: "+suma);
}

12. Que lea 10 nmeros por teclado, los almacene en un array y muestre la media.
package 12;
public class media extends javax.swing.JFrame {
public media() {
initComponents();
}
private void btn_calcularActionPerformed(java.awt.event.ActionEvent evt) {
double q,r,s,t,u,v,w,x,y,z;
q=Integer.parseInt(txt_num1.getText());
r=Integer.parseInt(txt_num2.getText());
s=Integer.parseInt(txt_num3.getText());
t=Integer.parseInt(txt_num4.getText());
u=Integer.parseInt(txt_num5.getText());
v=Integer.parseInt(txt_num6.getText());
w=Integer.parseInt(txt_num7.getText());
x=Integer.parseInt(txt_num8.getText());
y=Integer.parseInt(txt_num9.getText());
z=Integer.parseInt(txt_num10.getText());
double vector [] = {q,r,s,t,u,v,w,x,y,z};
double media = q+r+s+t+u+v+w+x+y+z;
lbl_result.setText("La media es "+media);
}

13. Que mediante un array almacene nmeros tanto positivos como negativos y los
muestre ordenados.
package vectorordenar;
public class ordenar extends javax.swing.JFrame {
public ordenar() {
initComponents();
}
private void BbotongenaraActionPerformed(java.awt.event.ActionEvent evt) {

int aux,q,r,s,t,u,v,w,x,y,z;
q=Integer.parseInt(uno.getText());
r=Integer.parseInt(dos.getText());
s=Integer.parseInt(tres.getText());
t=Integer.parseInt(cuatro.getText());
u=Integer.parseInt(cinco.getText());
v=Integer.parseInt(seis.getText());
w=Integer.parseInt(siete.getText());
x=Integer.parseInt(ocho.getText());
y=Integer.parseInt(nueve.getText());
z=Integer.parseInt(diez.getText());
int vector [] = {q,r,s,t,u,v,w,x,y,z};
String vect = "";
for (int i = 0; i < 10; i++) {
for (int j = i; j < 10; j++) {
if(vector[ i ] < vector[ j ]){
aux = vector[ i ];
vector[ i ] = vector[ j ];
vector[ j ] = aux;
vect += vector[ i ]+" ";
}}}
ordenar.setText(vect);
}

14.

Que rellene un array con 20 nmeros y luego busque un nmero concreto.

package numero;
public class concreto extends javax.swing.JFrame {
public concreto () {
initComponents();
}
private void btn_calcularActionPerformed(java.awt.event.ActionEvent evt) {
int buscado,f,g,h,k,l,m,n,,o,p,aux,q,r,s,t,u,v,w,x,y,z;
q=Integer.parseInt(txt_num1.getText());
r=Integer.parseInt(txt_num2.getText());
s=Integer.parseInt(txt_num3.getText());
t=Integer.parseInt(txt_num4.getText());
u=Integer.parseInt(txt_num5.getText());
v=Integer.parseInt(txt_num6.getText());
w=Integer.parseInt(txt_num7.getText());
x=Integer.parseInt(txt_num8.getText());
y=Integer.parseInt(txt_num9.getText());
z=Integer.parseInt(txt_num10.getText());
f=Integer.parseInt(txt_num11.getText());
g=Integer.parseInt(txt_num12.getText());
h=Integer.parseInt(txt_num13.getText());
k=Integer.parseInt(txt_num14.getText());

l=Integer.parseInt(txt_num15.getText());
m=Integer.parseInt(txt_num16.getText());
n=Integer.parseInt(txt_num17.getText());
=Integer.parseInt(txt_num18.getText());
o=Integer.parseInt(txt_num19.getText());
p=Integer.parseInt(txt_num20.getText());
buscado = Integer.parseInt(txt_busqueda.getText());
int vector [] = {q,r,s,t,u,v,w,x,y,z,f,g,h,k,l,m,n,,o,p};
for (int i = 0; i < 20; i++) {
if(buscado == vector[i]){
lbl_result.setText(""+i);
}} }

15. Que pinte un tablero de ajedrez, los peones con la letra P, las torres con T, los
caballos con C, los alfiles con A, el rey con R y la reina con M.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------16. Que muestre los primeros 100 nmeros de izquierda a derecha usando un array de
dos dimensiones.
package ejercicio16;
public class 2d extends javax.swing.JFrame {
public 2d() {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {
String vector="";
int vec[]= new int [100];
for(int i=1;i<=100;i++){
vec[i-1]=i;
vector+=vec[i-1]+" ";
if(i%50==0){
vector+="\n";
}
}
area.setText(vector );
}

17. Que muestre los primeros 100 nmeros de izquierda a derecha usando un array
de dos dimensiones, la ltima fila a mostrar la suma de sus respectivas columnas.

package matriz;
public class sumamatriz extends javax.swing.JFrame {
public sumamatriz() {
initComponents();
}
private void botongenerarActionPerformed(java.awt.event.ActionEvent evt) {
int mat[][]= new int[11][10];
String vector="";
int x=1,suma=0;
for (int f=0;f<10;f++){
for (int c=0;c<10;c++){
mat[f][c]=x;
x++;
vector+= mat[f][c]+" ";}
vector+="\n";}
for (int f=0;f<10;f++){
for (int c=0;c<10;c++){
suma=suma+mat[c][f]; }
mat[10][f]= suma;
vector+= mat[10][f]+" ";}
area.setText(vector);
}

18. Que rellene un array de dos dimensiones con nmeros pares, lo pinte y despus
que pida una posicin X,Y y mostrar el nmero correspondiente.
package javaapplication3;
public class matrizacendenteparesypedirpos extends javax.swing.JFrame {
public matrizacendenteparesypedirpos() {
initComponents();
} int mat[][]= new int[11][10];
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int a= Integer.parseInt(txt1.getText());
int b=Integer.parseInt(txt1.getText());
String vector="";
int x=2,suma=0;
for (int f=0;f<10;f++){
for (int c=0;c<10;c++){
mat[f][c]=x;
x=x+2;
vector+= mat[f][c]+" ";
}vector+="\n";
}for (int f=0;f<10;f++){

for (int c=0;c<10;c++){


suma=suma+mat[c][f];
}mat[10][f]= suma;
vector+= mat[10][f]+" ";
}txa.setText(vector);
txt3.setText(mat[a][b]+" ");
}

19. Que rellene una matriz de 3x3 y muestre su traspuesta (la traspuesta se consigue
intercambiando filas por columnas y viceversa).
package javaapplication3;
import java.util.Random;
public class matriz3x3transpuesta extends javax.swing.JFrame {
public matriz3x3transpuesta() {
initComponents();
} int mat[][]= new int [3][3];
int trans[][]= new int [3][3];
String vector1="";
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Random rnd = new Random();
String vector="";
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
mat[i][j]= rnd.nextInt(9);
vector+= mat[i][j]+" ";
}vector+="\n";
}txa1.setText(vector);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
trans[j][i]=mat[i][j];
vector1+= trans[i][j]+" ";
}vector1+="\n";
}txa2.setText(vector1);
}}

20. Que lea una cadena y la muestre al revs.


package javaapplication3;
public class num3roiMenorAmayor extends javax.swing.JFrame {
public num3roiMenorAmayor() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int vec[] = new int[3];
int aux;
vec[0] = Integer.parseInt(txt1.getText());
vec[1] = Integer.parseInt(txt2.getText());
vec[2] = Integer.parseInt(txt3.getText());
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (vec[i] > vec[j]) {
aux = vec[i];
vec[i] = vec[j];
vec[j] = aux;
}}}txt11.setText(vec[0]+" "+vec[1]+" "+vec[2]);
}

21. Que lea una cadena y diga cuantas vocales hay.


package pkg25.cuenta_vocales;
public class cuenta extends javax.swing.JFrame {
public cuenta() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String Palabra =(cadena.getText());
int contador = 0;
for(int x=0;x<Palabra.length();x++) {
}
for(int x=0;x<Palabra.length();x++) {
if ((Palabra.charAt(x)=='a') || (Palabra.charAt(x)=='e') || (Palabra.charAt(x)=='i') ||
(Palabra.charAt(x)=='o') || (Palabra.charAt(x)=='u')){
contador++;

}
}
resul.setText("La palabra " +"("+Palabra+")"+" contiene " + contador + " vocales
");
}

22. Que lea una cadena y diga cuantas maysculas hay.


package pkg22.cuenta_mayusculas;
public class cuenta extends javax.swing.JFrame {
public cuenta() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String Palabra =(cadena.getText());
int n = 0;
for (int i = 0; i < Palabra.length(); i++) {
if(Palabra.charAt(i)> 64 && Palabra.charAt(i)<91)
n++;
}
resul.setText("La palabra " +"("+Palabra+")"+" contiene " + n + " mayusculas ");
}

23. Que lea una cadena y la encripte sumando 3 al cdigo ASCII de cada carcter.
Mostrar por pantalla.
package pkg23.encripte;
import java.util.*;
public class encripte1 extends javax.swing.JFrame {
public encripte1() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int sum = 0;
int x;
String encriptado="";
String Palabra =(cadena.getText());
char frase[] = new char[50];
int aux=3;
for (x = 0; x < Palabra.length();x++){

frase[x]=Palabra.charAt(x);
}
for (x = 0; x < Palabra.length();x++)
{
frase[x]=(char) (frase[x]+3);
encriptado+=frase[x];
}
resul.setText(encriptado);
}

24. Que gestione los datos de stock de una tienda de comestibles, la informacin a
recoger ser: nombre del producto, precio, cantidad en stock. La tienda dispone de
10 productos distintos. El programa debe ser capaz de:
Dar de alta un producto nuevo (ordenar array por precio).
Buscar un producto por su nombre.
Modificar el stock y precio de un producto dado.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------25. Que gestiona las notas de una clase de 20 alumnos de los cuales sabemos el
nombre y la nota. El programa debe ser capaz de:
Buscar un alumno.
Modificar su nota.
Realizar la media de todas las notas.
Realizar la media de las notas menores de 5.
Mostrar el alumno que mejores notas ha sacado.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------26. Mostrar el alumno que peores notas ha sacado.
package pkg23.encripte;
import java.util.*;
public class encripte1 extends javax.swing.JFrame {
public encripte1() {
initComponents();
}

private void operacionActionPerformed(java.awt.event.ActionEvent evt) {


double alumno1=Double.parseDouble(txt1.getText());
double alumno2=Double.parseDouble(txt2.getText());
double alumno3=Double.parseDouble(txt3.getText());
double alumno4=Double.parseDouble(txt4.getText());
if(alumno1 <alumno2&&alumno1<alumno3&&alumno1<alumno4){
String resp=Double.toString(alumno1);
txtrespu.setText(resp);
}else{
if(alumno2<alumno1&&alumno2<alumno3&&alumno2<alumno4){
String res=Double.toString(alumno2);
txtrespu.setText(res);
}else{
if(alumno3<alumno1&&alumno3<alumno2&&alumno3<alumno4){
String respu=Double.toString(alumno3);
txtrespu.setText(respu);
}else{
if(alumno4<alumno1&&alumno4<alumno2&&alumno4<alumno3){
String respu=Double.toString(alumno4);
txtrespu.setText(respu);
}else{
if (alumno1==alumno2&&alumno1==alumno3&&alumno1==alumno4){
String respuestas=Double.toString(alumno1);
txtrespu.setText(respuestas+ "LOS NUMEROS SON IGUALES");
}else{
if(alumno1==alumno2&&alumno1!= alumno3&&alumno1!=alumno4){
String respuestas=Double.toString(alumno1);
txtrespu.setText(respuestas+"EL NUMERO 1 Y 2 SON IGUALES");
} else {
if(alumno1==alumno3&&alumno1!= alumno2&& alumno1!= alumno4){
String respuestas=Double.toString(alumno1);
txtrespu.setText(respuestas+"EL NUMERO 1 Y 3 SON IGUALES");
}else {
if(alumno1==alumno4&&alumno1!= alumno2&&alumno1!= alumno3){
String respuestas=Double.toString(alumno1);
txtrespu.setText(respuestas+"EL NUMERO 1 Y 4 SON IGUALES");
}}}}}}}}}

27. Que pida un nmero del 1 al 5 y diga si es primo o no.


package primo;
public class verificar extends javax.swing.JFrame {

public verificar() {
initComponents();
}
private void operarActionPerformed(java.awt.event.ActionEvent evt) {
double numero=Double.parseDouble(obtener.getText());
double suma=0;
for(double i=0;i<=numero;i++){
if(numero%i==0){
suma++;}}
if(suma!=2){
res.setText("Numero no es primo");
}else{
res.setText("Numero si es primo");
}}

28. Que pida un nmero y diga si es par o impar.


package par_o_impar;
public class numeroparoimpar extends javax.swing.JFrame {
public numeroparoimpar() {
initComponents();
}
private void botonverificarActionPerformed(java.awt.event.ActionEvent evt) {
double num1=Double.parseDouble(numero.getText());
double resultado;
resultado=num1/2;
if(num1%2==0)
{respuesta.setText("EL NUMERO ES PAR");
}else
{respuesta.setText("EL NUMERO ES IMPAR");
}if(num1==0)
{System.out.println("EL NUMERO ES CERO");
}
}

29. Que pida un nmero del 1 al 7 y diga el da de la semana correspondiente.


package semana;
public class semana1 extends javax.swing.JFrame {
public semana1() {
initComponents();
}

private void botonverificarActionPerformed(java.awt.event.ActionEvent evt) {


double num1=Double.parseDouble(numero.getText());
if ((num1<1)&&(num1>7)){
//String resp=Double.toString(num1);
dia.setText("ERROR");
}
if (num1==1)
{
dia.setText("LUNES ");
}
if (num1==2)
{
dia.setText("MARTES");
}
if (num1==3)
{
dia.setText("MIERCOLES ");
}
if (num1==4)
{
dia.setText("JUEVES ");
}
if (num1==5)
{
dia.setText("VIERNES ");
}
if (num1==6)
{
dia.setText("SABADO");
}
if (num1==7)
{
dia.setText("DOMINGO ");
}}

30. Que pida un nmero del 1 al 12 y diga el nombre del mes correspondiente.
package ejercicio30;
public class numeromes extends javax.swing.JFrame {
public numeromes() {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
double num1=Double.parseDouble(numero.getText());
if ((num1<1)&&(num1>12)){
//String resp=Double.toString(num1);

respuesta.setText("ERROR");
}
if (num1==1)
{
respuesta.setText("ENERO");
}
if (num1==2)
{
respuesta.setText("FEBRERO");
}
if (num1==3)
{
respuesta.setText("MARZO");
}
if (num1==4)
{
respuesta.setText("ABRIL");
}
if (num1==5)
{
respuesta.setText("MAYO");
}
if (num1==6)
{
respuesta.setText("JUNIO");
}
if (num1==7)
{
respuesta.setText("JULIO");
}
if (num1==8)
{
respuesta.setText("AGOSTO");
}
if (num1==9)
{
respuesta.setText("SEPTIEMBRE");
}
if (num1==10)
{
respuesta.setText("OCTUBRE");
}
if (num1==11)
{
respuesta.setText("NOVIEMBRE");
}
if (num1==12)
{
respuesta.setText("DICIEMBRE");
}
}

31. Que pida 3 nmeros y los muestre en pantalla de menor a mayor.


package ordenar;
public class menoramayor extends javax.swing.JFrame {
public menoramayor() {
initComponents();
}
private void botongeneradorActionPerformed(java.awt.event.ActionEvent evt) {
int a,b,c,Mayor,Medio,Menor;
a=(int)Double.parseDouble(numero1.getText());
b=(int)Double.parseDouble(numero2.getText());
c=(int)Double.parseDouble(numero3.getText());
if(a>b&&a>c)
Mayor=a;
else
if(b>a&&b>c)
Mayor=b;
else
Mayor=c;
if(a<b&&a<c)
Menor=a;
else
if(b<a&&b<c)
Menor=b;
else
Menor=c;
Medio=(a+b+c)-(Mayor+Menor);
respuesta.setText(Menor+" "+Medio+" "+Mayor);
}

32. Que pida 3 nmeros y los muestre en pantalla de mayor a menor.


package mayoramenor;
public class ordenar extends javax.swing.JFrame {
public ordenar() {
initComponents();
}
private void botonverificarActionPerformed(java.awt.event.ActionEvent evt) {
int A,B,C;

A=(int)Double.parseDouble(uno.getText());
B=(int)Double.parseDouble(dos.getText());
C=(int)Double.parseDouble(tres.getText());
if(A >= B && A >= C)
{if(B >= C){
lblresp.setText(" \n " + A + " \n " + B + " \n " + C);
}else
{lblresp.setText(" \n " + A + " \n " + C + " \n " + B);}
}else if(B >= A && B >= C)
{if(C >= A){
lblresp.setText(" \n " + B + " \n " + C + " \n " + A);
}else{
lblresp.setText(" \n " + B + " \n " + A + " \n " + C);
}} else if(C >= A && C >= B)
{if(A >= B)
{
lblresp.setText(" \n " + C + " \n " + A + " \n " + B);
}
else
{
lblresp.setText(" \n " + C + " \n " + B + " \n " + A);
}}
}

33. Que pida 3 nmeros y los muestre en pantalla de mayor a menor en lneas
distintas. En caso de haber nmeros iguales se pintan en la misma lnea.
package lineas.distintas;
public class ORDENAR extends javax.swing.JFrame {
public ORDENAR() {
initComponents();
}
private void botonordenarActionPerformed(java.awt.event.ActionEvent evt) {
int A,B,C;
A=(int)Double.parseDouble(uno.getText());
B=(int)Double.parseDouble(dos.getText());
C=(int)Double.parseDouble(tres.getText());
if(A >= B && A >= C)
{if(B >= C)
{
areares.setText("" + A + "\n " + B + "\n" + C);
}else
{areares.setText("" + A + "\n " + C + "\n" + B);
}}

else if(B >= A && B >= C)


{if(C >= A)
{
areares.setText("" + B + "\n" + C + "\n" + A);
}else
{
areares.setText("" + B + "\n" + A + "\n" + C);
}}else if(C >= A && C >= B)
{if(A >= B)
{
areares.setText("" + C + "\n " + A + "\n" + B);
}else
{
areares.setText("" + C + "\n" + B + " \n" + A);
}}}

34. Que pida un nmero y diga si es positivo o negativo.


package numero;
public class postivo_negativo extends javax.swing.JFrame {
public positivo_negativo() {
initComponents();
}
private void botonverificarActionPerformed(java.awt.event.ActionEvent evt) {
int numero;
numero=(int)Double.parseDouble(numeros.getText());
if(numero>0)
{
respuesta.setText("El nmero es positivo");
}if(numero<0)
respuesta.setText("El nmero es negativo");
if(numero==0)
{
respuesta.setText("El nmero es neutro o cero");
}}

35. Que slo permita introducir los caracteres S y N.


package introducircaracteres;

import javax.swing.JOptionPane;
public class caracter extends javax.swing.JFrame {
public caracter() {
initComponents();
}
private void txtcKeyTyped(java.awt.event.KeyEvent evt) {
char c=evt.getKeyChar();
if(c!='S' && c!='N')evt.consume();
if(c!='S' && c!='N'){
JOptionPane.showMessageDialog ( null , "INGRESE UN CARACTER VALIDO S O
N" );
}}

36. Que pida un nmero y diga si es mayor de 100.


package numero;
public class Mayor extends javax.swing.JFrame {
public Mayor() {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
int num=Integer.parseInt(numeroingreso.getText());
if(num>100){
respuesta.setText("SI ES MAYOR QUE 100");
}else{
respuesta.setText("NO ES MAYOR QUE 100");
}}

37. Que pida una letra y detecte si es una vocal.


package vocal;
public class verificar extends javax.swing.JFrame {
public verificar () {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
char let=letara.getText().charAt(0);
if(let=='a'||let=='e'||let=='i'||let=='0'||let=='u'){
respuesta.setText("SI ES VOCAL");

}else{
respuesta.setText("NO ES VOCAL");
}}}

38. Que pida tres nmeros y detecte si se han introducido en orden creciente.
package creciente;
public class verificar extends javax.swing.JFrame {
public verificar() {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
int vector[] = new int[3];
int aux;
vector[0] = Integer.parseInt(uno.getText());
vector[1] = Integer.parseInt(dos.getText());
vector[2] = Integer.parseInt(tres.getText());
if(vector[0]<vector[1]&&vector[1]<vector[2]){
respuesta.setText("SI ESTAN EN ORDEN CRESIENTE");
}else{
respuesta.setText("N0 ESTAN EN ORDEN CRESIENTE");
}
}

39. Que pida tres nmeros y detecte si se han introducido en orden decreciente.
package decreciente;
public class verificador extends javax.swing.JFrame {
public verificador() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int vec[] = new int[3];
int aux;
vec[0] = Integer.parseInt(uno.getText());
vec[1] = Integer.parseInt(dos.getText());
vec[2] = Integer.parseInt(tres.getText());
if(vec[0]>vec[1]&&vec[1]>vec[2]){
respuesta.setText("SI ESTAN EN ORDEN DECENDIENTE");

}else{
respuesta.setText("N0 ESTAN EN ORDEN DECENDIENTE");
}
}

40. Que pida 10 nmeros y diga cul es el mayor y cual el menor.


package ordenar;
public class ordenar1 extends javax.swing.JFrame {
public ordenar1() {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
int vector[] = new int[10];
vector[0] = Integer.parseInt(uno.getText());
vector[1] = Integer.parseInt(dos.getText());
vector[2] = Integer.parseInt(tres.getText());
vector[3] = Integer.parseInt(cuatro.getText());
vector[4] = Integer.parseInt(seis.getText());
vector[5] = Integer.parseInt(cinco.getText());
vector[6] = Integer.parseInt(siete.getText());
vector[7] = Integer.parseInt(ocho.getText());
vector[8] = Integer.parseInt(nueve.getText());
vector[9] = Integer.parseInt(diez.getText());
for (int i = 0; i < 10; i++) {
for (int j = i + 1; j < 10; j++) {
if (vector[i] > vector[j]) {
int aux = vector[i];
vector[i] = vector[j];
vector[j] = aux;
}}}
respuesta.setText(vector[9]+" es el mayor y "+vector[1]+" es el menor");
}

41. Que pida tres nmeros e indicar si el tercero es igual a la suma del primero y el
segundo.
package verificar;

public class nsuma extends javax.swing.JFrame {


public nsuma() {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
int vec[] = new int[3];
int aux=0;
vec[0] = Integer.parseInt(uno.getText());
vec[1] = Integer.parseInt(dos.getText());
vec[2] = Integer.parseInt(tres.getText());
aux=vec[0]+vec[1];
if(aux==vec[2]){
respuesta.setText(vec[2]+" es el resultado de sumar el primero y el
segundo");
}}

42. Que muestre un men que contemple las opciones Archivo, Buscar y Salir,
en caso de que no se introduzca una opcin correcta se notificar por pantalla.
package menu;
public class items extends javax.swing.JFrame {
public items() {
initComponents();
}
private void btnotrosActionPerformed(java.awt.event.ActionEvent evt) {
RESPUESTA.setText(" OPCION INCORRECTA");
}
private void btnbuscarActionPerformed(java.awt.event.ActionEvent evt) {
RESPUESTA.setText(" OPCION CORRECTA");
}
private void btnsalirActionPerformed(java.awt.event.ActionEvent evt) {
RESPUESTA.setText(" OPCION CORRECTA");
}
private void btnarchivoActionPerformed(java.awt.event.ActionEvent evt) {
RESPUESTA.setText(" OPCION CORRECTA");
}

43. Que tome dos nmeros y diga si ambos son primos.

package javaapplication3;
public class numprimos2 extends javax.swing.JFrame {
public numprimos2() {
initComponents();
}
private void
BOTONVERIFICADORActionPerformed(java.awt.event.ActionEvent evt) {
int vec[]= new int[2];
vec[0]=Integer.parseInt(uno.getText());
vec[1]=Integer.parseInt(uno.getText());
int cont=0;
int d=0;
int i=1;
while(i<=vec[0]) {
if (vec[0]%i==0)
{
d=d+1;
}
i=i+1;
}
if(d==2)
{
respuesta.setText(" si son primos");
}
}

44. Que tome dos nmeros y diga si ambos son pares o impares.
package javaapplication3;
public class paresoinpa2 extends javax.swing.JFrame {
public paresoinpa2() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int vec[]= new int[2];
vec[0]=Integer.parseInt(UNO.getText());
vec[1]=Integer.parseInt(UNO.getText());
if(vec[0]%2==0&vec[1]%2==0){
RESPUESTA.setText(" si son pares");
}else{

RESPUESTA.setText(" son inpares");


}
}

45. Que tome tres nmeros y diga si la multiplicacin de los dos primeros es igual al
tercero.
package multi;
public class verificar extends javax.swing.JFrame {
public verficar() {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
int vec[] = new int[3];
int aux=0;
vec[0] = Integer.parseInt(uno.getText());
vec[1] = Integer.parseInt(dos.getText());
vec[2] = Integer.parseInt(tres.getText());
aux=vec[0]+vec[1];
if(aux==vec[2]){
respuesta.setText(vec[2]+" es el resultado de sumar el primero y el segundo");
}
}

46. Que tome tres nmeros y diga si el tercero es el resto de la divisin de los dos

primeros.
package generar;
public class generar1 extends javax.swing.JFrame {
public generar1() {
initComponents();
}
private void botonverificadorActionPerformed(java.awt.event.ActionEvent evt) {
int vect[] =new int [3];
int aux;
vect[0]= Integer.parseInt(uno.getText());
vect[1]= Integer.parseInt(dos.getText());
vect[2]= Integer.parseInt(tres.getText());
aux=vect[0]/vect[1];
if (aux==vect[2]){
respuesta.setText(vect[2]+"El resultado de dividir el primero y el segundo");
}
}

47. Que muestre un men donde las opciones sean Equiltero, Issceles y
Escaleno, pida una opcin y calcule el permetro del tringulo seleccionado.
package equilatero;
public class isosoles extends javax.swing.JFrame {
public isosoles() {
initComponents();
}
private void botoncalcularActionPerformed(java.awt.event.ActionEvent evt) {
int vect[] =new int [3];

int aux;
vect[0]= Integer.parseInt(dato1.getText());
vect[1]= Integer.parseInt(dato2.getText());
vect[2]= Integer.parseInt(dato3.getText());
aux=vect[0]+vect[1]+vect[2];
respuesta.setText(aux+"Es el perimetro");
}

48. Que pase de Kg a otra unidad de medida de masa, mostrar en pantalla un men
con las opciones posibles.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------49. Que lea un importe bruto y calcule su importe neto, si es mayor de 15.000 se le
aplicar un 16% de impuestos, en caso contrario se le aplicar un 10%.
package importe;
public class reporimporte extends javax.swing.JFrame {
public reporimporte() {
initComponents();
}
private void botoncalcularActionPerformed(java.awt.event.ActionEvent evt) {
double importe=Double.parseDouble(importebruto.getText());
double aux;
if (importe>15000){
aux=importe+(importe*0.16);
respuesta.setText(aux+"");
}else{
aux=importe+(importe*0.10);
respuesta.setText(aux+"");

}
}

50. Que lea una hora en hora:minutos:segundos y diga la hora que es un segundo
despus.
package calcular;
public class hora extends javax.swing.JFrame {
public hora() {
initComponents();
}
int[] vect=new int [3];
public void mostrar(){
horamas.setText(vect[0]+"");
minutosmas.setText(vect[1]+"");
minutosmas.setText(vect[2]+"");
}
private void botnrealizarActionPerformed(java.awt.event.ActionEvent evt) {
int aux;
vect[0]= Integer.parseInt(horaactual.getText());
vect[1]= Integer.parseInt(minutoactual.getText());
vect[2]= Integer.parseInt(segundoactual.getText());
if (vect[2]<59){
vect[2]=vect[2]+1;
mostrar();
}if (vect[2]==59){
vect[2]=0;
if (vect[1]==59){
vect[1]=0;
if (vect[0]==23){

vect[0]=0;
mostrar();
}else{
vect[0]=vect[0]+1;
mostrar ();}
}else{
vect[1]=vect[1]+1;
mostrar ();
}}}

51. Que calcule el sueldo que le corresponde al trabajador de una empresa que cobra
40.000 euros anuales, el programa debe realizar los clculos en funcin de los
siguientes criterios:
Si lleva ms de 10 aos en la empresa se le aplica un aumento del 10%.
Si lleva menos de 10 aos pero ms que 5 se le aplica un aumento del 7%.
Si lleva menos de 5 aos pero ms que 3 se le aplica un aumento del 5%.
Si lleva menos de 3 aos se le aplica un aumento del 3%.

S-ar putea să vă placă și