Commit bf1af131 by Cristhian Ortellado

Se agrego el trabajo

parents
import java.util.Random;
/**
* Ejercicio01
*/
public class Ejercicio01 {
public static void main(String[] args) {
int vector[]=new int[10];
Random rnd = new Random();
int mayor=0;
for (int i = 0; i < vector.length; i++) {
int numero = rnd.nextInt(11)-5;
vector[i] = numero;
if (mayor<numero) {
mayor = numero;
}
System.out.println(vector[i]);
}
System.out.println("El mayor elemento es "+mayor);
}
}
\ No newline at end of file
import java.util.ArrayList;
import java.util.Map;
import java.util.Random;
public class Ejercicio02 {
public static void main(String[] args) {
int vector[]=new int[100];
Random rnd = new Random();
for (int i = 0; i < vector.length; i++) {
int numero = rnd.nextInt(61)-30;
vector[i]= numero;
}
int mayor=0;
int indice=0;
ArrayList nroNoPresente = new ArrayList<Integer>();
for (int i = -30; i <= 30; i++) {
int sum = 0;
for (int j = 0; j < vector.length; j++) {
if (i==vector[j]) {
sum++;
}
}
if (mayor<sum) {
mayor=sum;
indice = i;
}
if (sum==0)
nroNoPresente.add(i);
else
System.out.println("El numero "+i+" se repite "+sum);
}
System.out.println("\n\n\nEl numero que mas se repite es "+indice);
System.out.println("Los numeros que no estan presentes son ");
for (int i = 0; i < nroNoPresente.size(); i++) {
System.out.println(nroNoPresente.get(i));
}
}
}
public class Ejercicio03 {
public static void main(String[] args) {
System.out.println( esPalindrome("WAS IT A CAR OR A CAT I SAW"));
}
static boolean esPalindrome(String cadena){
String oracion =cadena.replaceAll("\\s","");
int lon =oracion.length();
for (int i = 0; i < lon/2; i++) {
if (!(oracion.charAt(i)==oracion.charAt(lon-i-1))) {
return false;
}
}
return true;
}
}
import java.util.Scanner;
public class Ejercicio04 {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
System.out.println("Ingrese una cadena");
String cadena = entrada.nextLine();
int vec[]=new int[cadena.length()];
for (int i = 0; i < vec.length; i++) {
vec[i]=Integer.parseInt("0"+cadena.charAt(i));
System.out.println(vec[i]);
}
entrada.close();
}
}
Intrucciones
1) Compilar el ejercicio utilizando javac nombreArchivo.java
2) Ejecutar utilizando java nombreArchivo
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment