Вы находитесь на странице: 1из 5

/*

* To change this license header, choose License Headers in Project


Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tallerunidad4;

import java.util.Scanner;

/**
*
* @author adminstrador
*/
public class Ejercicio1 {
public static void main(String[] args) {

Scanner teclado = new Scanner(System.in);


int array[] = new int[5];

for (int i = 0; i < array.length; i++) {


System.out.print("Ingrese dato " + (i + 1) + ": ");
array[i] = teclado.nextInt();
}
int mayor = 0;
int menor = 0;

menor = array[0];
mayor = menor;

for (int i = 0; i < array.length; i++) {


if (array[i] > mayor) {
mayor = array[i];
}
if (array[i] < menor) {
menor = array[i];
}
}
System.out.println("El mayor valor es: " + mayor);
System.out.println("El menor valor es: " + menor);
}

}
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tallerunidad4;

import java.util.Scanner;

public class Ejercicio2 {


public static void main(String[] args) {

Scanner teclado = new Scanner(System.in);


int vNumero[] = new int[5];
int x = 0;

for (int i = 0; i < vNumero.length; i++) {


System.out.print("Ingrese dato " + (i + 1) + ": ");
vNumero[i] = teclado.nextInt();
}

while (x < vNumero.length) {


int contPrimo = 0;
for (int i = 1; i <= vNumero[x]; i++) {
if (vNumero[x] % i == 0) {
contPrimo++;
}

}
if (contPrimo == 2) {
System.out.println(" Numero primo es: " + vNumero[x]);
}
x = x + 1;
}

}
}
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tallerunidad4;

import java.util.Scanner;

public class Ejercicio3 {


public static void main(String[] args) {

Scanner teclado = new Scanner(System.in);


int vNumero[] = new int[5];
int x = 0;
int contPar = 0;
int contImpar = 0;
for (int i = 0; i < vNumero.length; i++) {
System.out.print("Ingrese dato " + (i + 1) + ": ");
vNumero[i] = teclado.nextInt();
}

for (int i = 0; i < vNumero.length; i++) {


if (vNumero[i] % 2 == 0) {
contPar++;
}else{
contImpar++;
}
}
System.out.println(" Cantidad de numeros pares: " + contPar);
System.out.println(" Cantidad de numeros impares: " + contImpar);
}
}
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tallerunidad4;

import java.util.Scanner;

public class Ejercicio4 {


public static void main(String[] args) {

Scanner teclado = new Scanner(System.in);


int vNumero[] = new int[5];
int aux;

for (int i = 0; i < vNumero.length; i++) {


System.out.print("Ingrese dato " + (i + 1) + ": ");
vNumero[i] = teclado.nextInt();
}
System.out.println(" vector desordenado: ");
for (int i = 0; i < vNumero.length; i++) {
System.out.print( vNumero[i] + ": ");
}
for (int i = 0; i < vNumero.length; i++) {
for (int j = i + 1; j < vNumero.length; j++) {
if(vNumero[i] > vNumero[j]){
aux = vNumero[i];
vNumero[i] = vNumero[j];
vNumero[j] = aux;
}
}
}
System.out.print("\n");
System.out.println(" vector ordenado ascendentemente: ");
for (int i = 0; i < vNumero.length; i++) {
System.out.print( vNumero[i] + ": ");
}
}
}
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tallerunidad4;

import java.util.Scanner;

public class Ejercicio6 {


public static void main(String[] args) {

Scanner teclado = new Scanner(System.in);


int vNumero[] = new int[10];

for (int i = 0; i < vNumero.length; i++) {


System.out.print("Ingrese dato " + (i + 1) + ": ");
vNumero[i] = teclado.nextInt();
}

System.out.println(" Mostrando elementos del vector original: ");


for (int i = 0; i < vNumero.length; i++) {
System.out.print( vNumero[i] + ": ");

}
System.out.print("\n");
System.out.println(" Mostrando elementos del vector en orden inverso:
");
for (int i = vNumero.length - 1; i > -1; i--) {
System.out.print( vNumero[i] + ": ");
}
}
}

Вам также может понравиться