martes, 21 de mayo de 2013
BIENVENIDOS A LOS EJERCICIOS JAVA
public static void main(String[] parametro) {
System.out.println("BIENVENIDOS A LOS EJERCICIOS JAVA");
}
}
CARGAR EL VECTOR DE ? ELEMENTOS DE TIPO SOLO ENTEROS .ORDENAR
import java.util.Scanner;
public class Ejercicio24 {
private Scanner teclado;
private int[] vec;
public void cargar() {
teclado=new Scanner(System.in);
System.out.print("Cuantos elementos tendrá el vector:");
int cant;
cant=teclado.nextInt();
vec=new int[cant];
for(int f=0;f<vec.length;f++) {
System.out.print("Ingrese elemento:");
vec[f]=teclado.nextInt();
}
}
public void ordenar() {
for(int k=0;k<vec.length;k++) {
for(int f=0;f<vec.length-1-k;f++) {
if (vec[f]>vec[f+1]) {
int aux;
aux=vec[f];
vec[f]=vec[f+1];
vec[f+1]=aux;
}
}
}
}
public void imprimir() {
System.out.println("Vector ordenados de menor a mayor.");
for(int f=0;f<vec.length;f++) {
System.out.println(vec[f]);
}
}
public static void main(String[] ar) {
Ejercicio24 pv=new Ejercicio24 ();
pv.cargar();
pv.ordenar();
pv.imprimir();
}
}
DEFINIR UN VECTOR DONDE SE ALAMACENAR LOS NOMBRES DE 5 PAÍSES Y ORDENAR DE FORMA ALFABETICA
import java.util.Scanner;
public class Ejercicio23{
private Scanner teclado;
private String[] paises;
public void cargar() {
teclado=new Scanner(System.in);
paises=new String[5];
for(int f=0;f<paises.length;f++) {
System.out.print("Ingrese el nombre del pais:");
paises[f]=teclado.next();
}
}
public void ordenar() {
for(int k=0;k<4;k++) {
for(int f=0;f<4-k;f++) {
if (paises[f].compareTo(paises[f+1])>0) {
String aux;
aux=paises[f];
paises[f]=paises[f+1];
paises[f+1]=aux;
}
}
}
}
public void imprimir() {
System.out.println("Paises ordenados en forma alfabética:");
for(int f=0;f<paises.length;f++) {
System.out.println(paises[f]);
}
}
public static void main(String[] ar) {
Ejercicio23 pv=new Ejercicio23();
pv.cargar();
pv.ordenar();
pv.imprimir();
}
}
http://www.youtube.com/watch?v=1ETmI8UcUpU
SE DEBE CREAR UN VECTOR DONDE ALMACENAR 5 SUELDOS. ORDENAR EL VECTOR SUELDOS DE MENOR A MAYOR.
import java.util.Scanner;
public class Ejercicio22 {
private Scanner teclado;
private int[] sueldos;
public void cargar() {
teclado=new Scanner(System.in);
sueldos=new int[5];
for(int f=0;f<sueldos.length;f++) {
System.out.print("Ingrese el sueldo:");
sueldos[f]=teclado.nextInt();
}
}
public void ordenar() {
for(int k=0;k<4;k++) {
for(int f=0;f<4-k;f++) {
if (sueldos[f]>sueldos[f+1]) {
int aux;
aux=sueldos[f];
sueldos[f]=sueldos[f+1];
sueldos[f+1]=aux;
}
}
}
}
public void imprimir() {
System.out.println("Sueldos ordenados de menor a mayor.");
for(int f=0;f<sueldos.length;f++) {
System.out.println(sueldos[f]);
}
}
public static void main(String[] ar) {
Ejercicio22 pv=new Ejercicio22();
pv.cargar();
pv.ordenar();
pv.imprimir();
}
}
http://www.youtube.com/watch?v=PzgJqiO3bHM
lunes, 13 de mayo de 2013
CREAR UNA MATRIZ DE 2 FILAS Y 5 COLUMNAS. REALIZAR LA CARGA DE COMPONENTES OOR COLUMNA (ES DECIR PRIMERO INGRESAR TODA LA PRIMER COLUMNA, LUEGO LA SEGUNDA COLUMNA Y ASI SUCESIVAMENTE) IMPRIMIR LUEGO LA MATRIZ.
import java.util.Scanner;
public class ejercicio21 {
private Scanner teclado;
private int[][] mat;
private Scanner teclado;
public void cargar() {
teclado=new Scanner(System.in);
mat=new int[2][5];
System.out.println("Carga de la matriz por columna:");
for(int c=0;c<5;c++) {
for(int f=0;f<2;f++) {
System.out.print("Ingrese componente " + " de la fila " + f + " y la columna "+ c + " :");
mat[f][c]=teclado.nextInt();
}
}
}
public void imprimir() {
for(int f=0;f<2;f++) {
for(int c=0;c<5;c++) {
System.out.print(mat[f][c]+" ");
}
System.out.println();
}
}
public static void main(String[] ar) {
ejercicio21 ma=new ejercicio21();
ma.cargar();
ma.imprimir();
}
}
http://www.youtube.com/watch?v=yjCDmtDtqPc
CREAR Y CARGAR UNA MATRIZ DE 4 FILAS POR 4 COLUMNAS IMPRIMIR EN FORMA DIAGONAL
import java.util.Scanner;
public class ejericio20 {
private Scanner teclado;
private int[][] mat;
public void cargar() {
teclado=new Scanner(System.in);
mat=new int[4][4];
for(int f=0;f<4;f++) {
for(int c=0;c<4;c++) {
System.out.print("Ingrese componente:");
mat[f][c]=teclado.nextInt();
}
}
}
public void imprimirDiagonalPrincipal() {
for(int k=0;k<4;k++) {
System.out.print(mat[k][k]+" ");
}
}
public static void main(String[] ar) {
ejericio20 ma=new ejericio20();
ma.cargar();
ma.imprimirDiagonalPrincipal();
} }
http://www.youtube.com/watch?v=gqYvZHElbhU
HACER UNA MATRIZ DE 3 FILAS X 5 COLUMNAS DE TIPO INT, CARGAR SUS COMPONENTES Y LUEGO IMPRIMIRLAS COMO MENSAJE
import java.util.Scanner;
public class ejercicio19{
private Scanner teclado;
private int[][] mat;
public void cargar() {
teclado=new Scanner(System.in);
mat=new int[3][5];
for(int f=0;f<3;f++) {
for(int c=0;c<5;c++) {
System.out.print("Ingrese componente:");
mat[f][c]=teclado.nextInt();
}
}
}
public void imprimir() {
for(int f=0;f<3;f++) {
for(int c=0;c<5;c++) {
System.out.print(mat[f][c]+" ");
}
System.out.println();
}
}public static void main(String[] ar) {
ejercicio19 ma=new ejercicio19();
ma.cargar();
ma.imprimir();
}
}
http://www.youtube.com/watch?v=gqYvZHElbhU
OBTENER EN UN VECTOR LOS NOMBRES DE 5 CONTINENTES Y EN OTRO VECTOR LA CANTIDAD DE HABITANTES DEL MISMO. ORDENAR ALFABETICAMENTE E IMPRIMIR LOS RESULTADOS. POR ULTIMO ORDENAR CON RESPECTO A LA CANTIDAD DE HABITANTES E IMPRIMIR.
import java.util.Scanner;
public class Ejercicio18{
private Scanner teclado;
private String[] paises;
private int[] habitantes;
private Scanner teclado;
public void cargar() {
teclado=new Scanner(System.in);
paises=new String[5];
habitantes=new int[5];
System.out.println("Carga de paises y habitantes");
for(int f=0;f<paises.length;f++) {
System.out.print("Ingese el nombre del pais:");
paises[f]=teclado.next();
System.out.print("Ingrese la cantidad de habitantes:");
habitantes[f]=teclado.nextInt();
}
}
public void ordenarPorNombres() {
for(int k=0;k<paises.length;k++) {
for(int f=0;f<paises.length-1-k;f++) {
if (paises[f].compareTo(paises[f+1])>0) {
String auxpais;
auxpais=paises[f];
paises[f]=paises[f+1];
paises[f+1]=auxpais;
int auxhabitante;
auxhabitante=habitantes[f];
habitantes[f]=habitantes[f+1];
habitantes[f+1]=auxhabitante;
}
}
}
}
public void ordenarPorHabitantes() {
for(int k=0;k<paises.length;k++) {
for(int f=0;f<paises.length-1-k;f++) {
if (habitantes[f]<habitantes[f+1]) {
String auxpais;
auxpais=paises[f];
paises[f]=paises[f+1];
paises[f+1]=auxpais;
int auxhabitante;
auxhabitante=habitantes[f];
habitantes[f]=habitantes[f+1];
habitantes[f+1]=auxhabitante;
}
}
}
}
public void imprimir() {
for(int f=0;f<paises.length;f++) {
System.out.println(paises[f] + " - " + habitantes[f]);
}
}
public static void main(String[] ar) {
Ejercicio18 pv=new Ejercicio18();
pv.cargar();
pv.ordenarPorNombres();
System.out.println("Ordenados alfabéticamente");
pv.imprimir();
pv.ordenarPorHabitantes();
System.out.println("Ordenados por cantidad de habitnates");
pv.imprimir();
}
}
http://www.youtube.com/watch?v=fmpAIKtmKCo
REALIZAR UN PROGRAMA QUE PERMITA INGRESARLOS NOMBRES DE 5 ALUMNOS Y SUS NOTAS . LUEGO ORDENAR LAS NOTAS DE MAYOR A MENOR. IMPRIMIR LAS NOTAS Y LOS NOMBRES DE LOS ALUMNOS.
import java.util.Scanner;
public class Ejercicio17 {
private Scanner teclado;
private String[] nombres;
private int[] notas;
public void cargar() {
teclado=new Scanner(System.in);
nombres=new String[5];
notas=new int[5];
System.out.println("Carga de nombres y notas");
for(int f=0;f<nombres.length;f++) {
System.out.print("Ingese el nombre del alumno:");
nombres[f]=teclado.next();
System.out.print("Ingrese la nota del alumno:");
notas[f]=teclado.nextInt();
}
}
public void ordenar() {
for(int k=0;k<notas.length;k++) {
for(int f=0;f<notas.length-1-k;f++) {
if (notas[f]<notas[f+1]) {
int auxnota;
auxnota=notas[f];
notas[f]=notas[f+1];
notas[f+1]=auxnota;
String auxnombre;
auxnombre=nombres[f];
nombres[f]=nombres[f+1];
nombres[f+1]=auxnombre;
}
}
}
}
public void imprimir() {
System.out.println("Nombres de alumnos y notas de mayor a menor");
for(int f=0;f<notas.length;f++) {
System.out.println(nombres[f] + " - " + notas[f]);
}
}
public static void main(String[] ar) {
Ejercicio17 pv=new Ejercicio17();
pv.cargar();
pv.ordenar();
pv.imprimir();
}
}
miércoles, 8 de mayo de 2013
INGRESAR 3 VALORES POR TECLADO Y MOSTRAR EL MAYOR Y MENOR DE ELLOS
import java.util.Scanner;
public class ejercicio16{
public void cargarValores() {
Scanner teclado=new Scanner(System.in);
System.out.print("Ingrese primer valor:");
int valor1=teclado.nextInt();
System.out.print("Ingrese segundo valor:");
int valor2=teclado.nextInt();
System.out.print("Ingrese tercer valor:");
int valor3=teclado.nextInt();
int mayor,menor;
mayor=calcularMayor(valor1,valor2,valor3);
menor=calcularMenor(valor1,valor2,valor3);
System.out.println("El valor mayor de los tres es:"+mayor);
System.out.println("El valor menor de los tres es:"+menor);
}
public int calcularMayor(int v1,int v2,int v3) {
int m;
if(v1>>v2 && v1>v3) {
m=v1;
} else {
if(v2>v3) {
m=v2;
} else {
m=v3;
}
}
return m;
}
public int calcularMenor(int v1,int v2,int v3) {
int m;
if(v1<v2 && v1<v3) {
m=v1;
} else {
if(v2<v3) {
m=v2;
} else {
m=v3;
}
}
return m;
}
public static void main(String[] ar) {
MayorMenor maymen=new MayorMenor();
maymen.cargarValores();
}
}
http://www.youtube.com/watch?v=-2MCKEaVxt8
INGRESAR VALORES ENTEROS Y MOSTRAR LA TABLA DE MULTIPLICACIÓN DEL VALOR Y FINALIZAR EL PROGRAMA AL INGRESAR -1
import java.util.Scanner;
public class ejercicio15 {
public void cargarValor() {
Scanner teclado=new Scanner(System.in);
int valor;
do {
System.out.print("Ingrese valor:");
valor=teclado.nextInt();
if (valor!=-1) {
calcular(valor);
}
} while (valor!=-1);
}
public void calcular(int v) {
for(int f=v;f<=v*10;f=f+v) {
System.out.print(f+"-");
}
}
public static void main(String[] ar) {
TablaMultiplicar tabla;
tabla=new TablaMultiplicar();
tabla.cargarValor();
}
}
http://www.youtube.com/watch?v=RU8iMht73EM
INGRESAR DOS NOMBRES Y MOSTRAR SI SON IGUALES O DISTINTOS
import java.util.Scanner;
public class ejercicio14 {
public static void main(String[] ar) {
Scanner teclado=new Scanner(System.in);
String nombre1,nombre2;
System.out.print("Ingrese primer nombre:");
apellido1=teclado.next();
System.out.print("Ingrese segundo nombre:");
nombre2=teclado.next();
if (nombre1.equals(nombre2)) {
System.out.print("Los nombres son iguales");
} else {
System.out.print("Los nombres son distintos");
}
}
}
INGRESAR EL NOMBRE Y LA EDAD DE DOS PERSONAS Y MOSTRAR EL MAYOR DE ELLOS
import java.util.Scanner;
public class ejercicio13 {
public static void main(String[] ar) {
Scanner teclado=new Scanner(System.in);
String nombre1,nombre2;
int edad1,edad2;
System.out.print("Ingrese el nombre:");
nombre1=teclado.next();
System.out.print("Ingrese edad:");
edad1=teclado.nextInt();
System.out.print("Ingrese el nombre:");
nombre2=teclado.next();
System.out.print("Ingrese edad:");
edad2=teclado.nextInt();
System.out.print("La persona de mayor edad es:");
if (edad1>edad2) {
System.out.print(nombre1);
} else {
System.out.print(nombre2);
}
}
}
jueves, 2 de mayo de 2013
REALIZAR UN PROGRAMA QUE SOLICITE INGRESAR 10 NOTAS Y NOS INFORME CUANTOS TIENEN NOTAS MAYORES ,MENORES O IGUALES A 7/10
import java.util.Scanner;
public class ejercicio12 {
public static void main(String[] ar) {
Scanner teclado=new Scanner(System.in);
int x,nota,conta1,conta2;
x=1;
conta1=0;
conta2=0;
while (x<=10) {
System.out.print("Ingrese nota:");
nota=teclado.nextInt();
if (nota>=7) {
conta1=conta1 + 1;
}else {
conta2=conta2 + 1;
}
x=x + 1;
System.out.print("Cantidad de alumnos con notas mayores o iguales a 7:");
System.out.println(conta1);
System.out.print("Cantidad de alumons con notas menores a 7:");
System.out.print(conta2);
}
}
ESCRIBIR UN PROGRAMA QUE SOLICITE LA CARGA DE UN VALOR POSITIVO Y NOS MUESTRE DESDE 1 HASTA EL VALOR INGRESADO
import java.util.Scanner;
public class ejercicio11 {
public static void main(String[] ar) {
Scanner teclado=new Scanner(System.in);
int n,x;
System.out.print("Ingrese el valor final:");
n=teclado.nextInt();
x=1;
while (x<=n) {
System.out.print(x);
System.out.print(" - ");
x = x + 1;
}
}
}
REALIZAR UN PROGRAMA QUE IMPRIMA EN PANTALLA DEL 1 AL 25
public class ejercicio10 {
public static void main(String[] ar) {
int x;
x=1;
while (x<=25) {
System.out.print(x);
System.out.print(" - ");
x = x + 1;
}
}
}
http://www.youtube.com/watch?v=zo9zp-6BAIk
SE INGRESAN POR TECLADO 3 NUMEROS SI LOS VALORES SON MENORES A 10 ,IMPRIMIR EN PANTALLA (TODOS LOS NÚMEROS SON MENORES A 10)
import java.util.Scanner;
public class ejercicio9 {
public static void main(String[] ar) {
Scanner teclado=new Scanner(System.in);
int num1,num2,num3;
System.out.print("Ingrese primer valor:");
num1=teclado.nextInt();
System.out.print("Ingrese segundo valor:");
num2=teclado.nextInt();
System.out.print("Ingrese tercer valor:");
num3=teclado.nextInt();
if (num1<10 && num2<10 && num3<10) {
System.out.print("Todos los números son menores a diez");
}
}
}
http://www.youtube.com/watch?v=Y-Nd2VHHmHQ
LEA UN PROGRMA 3 NUMEROS DE ELLOS DISTINTOS Y MOSTRAR EL MAYOR DE ELLOS
import java.util.Scanner;
public class ejercicio8{
public static void main(String[] ar) {
Scanner teclado=new Scanner(System.in);
int num1,num2,num3;
System.out.print("Ingrese primer valor:");
num1=teclado.nextInt();
System.out.print("Ingrese segundo valor:");
num2=teclado.nextInt();
System.out.print("Ingrese tercer valor:");
num3=teclado.nextInt();
if (num1>num2 && num1>num3) {
System.out.print(num1);
} else {
if (num2>num3) {
System.out.print(num2);
}else {
System.out.print(num3);
}
}
}
}
Suscribirse a:
Comentarios (Atom)







.jpg)
.jpg)
.jpg)



















