Commit 72d8bbcd by Silvia Barrientos

tarea java

parents
public class Ejercicio01 {
static final int X = 5;
static final int Y = -5;
public static void main(String[] args) {
int array[];
array = new int[10];
int mayor = -5;
for(int i = 0; i < array.length; i++){
array[i] = (int)(Math.random()*(X-Y+1)+Y);
System.out.printf("\t" + array[i]);
if(array[i] > mayor){
mayor = array[i];
}
}
System.out.printf("\nEl mayor elemento es: %d\n", mayor);
}
}
\ No newline at end of file
public class Ejercicio02 {
static final int X = 30;
static final int Y = -30;
static final int DIMENSION = 100;
public static void main(String[] args) {
int arrayNumeros[];
arrayNumeros = new int[61];
int indice = 0;
int array[];
array = new int[DIMENSION];
int contador = Y;
int mayor = 0;
int numero = 0;
for(int i = Y; i <= X; i++){
arrayNumeros[indice] = 0;
indice++;
}
for(int i = 0; i < array.length; i++){
array[i] = (int)(Math.random()*(X-Y+1)+Y);
System.out.printf(" " + array[i]);
}
indice = 0;
while(contador <= X){
for(int i = 0; i < array.length; i++){
if(contador == array[i]){
arrayNumeros[indice]++;
}
}
indice++;
contador++;
}
indice = 0;
System.out.printf("\nLos numeros que no estan presentes son: \n");
for(int i = Y; i <= X; i++){
if(arrayNumeros[indice] > mayor){
mayor = arrayNumeros[indice];
numero = i;
}
if(arrayNumeros[indice] == 0){
System.out.printf("\t %d", i);
}
indice++;
}
System.out.printf("\nEl numero que más se repite es: %d\n", + numero);
}
}
import java.util.Scanner;
public class Ejercicio03 {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
System.out.print("Ingrese una palabra: ");
String palabra = entrada.nextLine();
if(esPalíndrome(palabra)){
System.out.print("Es una palabra palíndrome\n");
}else{
System.out.print("No es una palabra palíndrome\n");
}
entrada.close();
}
public static boolean esPalíndrome(String palabraOrig){
String invertirPalabra = new StringBuilder(palabraOrig).reverse().toString();
invertirPalabra = invertirPalabra.replace(" ", "").replace(".", "").replace(",", "");
palabraOrig = palabraOrig.replace(" ", "").replace(".", "").replace(",", "");
if( invertirPalabra.equals(palabraOrig) ){
return true;
}else{
return false;
}
}
}
import java.util.Scanner;
public class Ejercicio04 {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
System.out.print("Ingrese cadena (solo digitos): ");
String cadena = entrada.nextLine();
entrada.close();
int array[];
array = new int[cadena.length()];
for(int i = 0; i < array.length; i++){
array[i] = Integer.parseInt(String.valueOf(cadena.charAt(i)));
}
for(int i = 0; i < array.length; i++){
System.out.printf(array[i] + "\t");
}
}
}
Para compilar los ejercicos
- Abrir el archivo en el editor de texto de preferencia.
- Compilar el archivo (F5 en VisualStudio Code).
- Se mostrar o requerira datos por consola.
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