PROYECTO JAVA FACIL
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
Suscribirse a:
Comentarios (Atom)







.jpg)
.jpg)
.jpg)


