Está en la página 1de 3

int num = sc.

nextInt();
int mayor = num;
boolean hayNegativos = false;
if (num<0) hayNegativos = true;

while (num¡=0)

-------------------------------------------------------------------
BUCLE: (ejercicio 8 del tema 3)

int num;
do {num = sc.nextInt(); } while (num==0);

// se repite el bucle mientras que el numero sea igual a 0, cuando se cambie a


otro numero pasará

------------------------------------------------------------------
EJERCICIO 5 DEL TEMA 2

import java.util.Scanner;

public class lunes {


public static void main (String args[]){
Scanner sc = new Scanner(System.in);
int x, y;

System.out.println("Introduce un numero entero");


x = sc.nextInt();
System.out.println("Introduce un numero entero");
y = sc.nextInt();

if (x==y)
{ System.out.println("Son iguales");
} else {
System.out.println("No son iguales");
}
sc.close();
}
}

------------------------------------------------------------------
ARRAYS:
//EJERCICIO 1 DEL TEMA 4

int n1, n2 n3, n4, n5;


n1 = sc.nextInt();
n2 = sc.nextInt();
n3 = sc.nextInt();
n4 = sc.nextInt();
n5 = sc.nextInt();

/* int[] n= new int [5];


int total;
for (int i=0; i<5; i++)
{
int n [i] = sc.nextInt();
total = total + [i];
}
int media = total/5;

int contador =0;


if (n[0]>media) contador = contador+1;
if (n[1]>media) contador = contador+1;
...
if (n[4]>media) contador = contador+1;

for (int i=0; i<5; i++)


if (n[i]>media) contador = contador+1;
}
System.out.println(contador);

*/

int total = n1+n2+n3+n4+n5;


int media = total/5;
------------------------------------------------------------------

EJERCICIO 2 DEL TEMA 4

import java.util.Scanner;

public class Repeticiones {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int[] notas = new int[10];

for (int i=0; i<10; i++) notas[i] = sc.nextInt();

int numeroMayor = notas[0];


int numeroMenor = notas[0];
for (int i=1; i<10; i++)
{
if (notas[i] > numeroMayor) numeroMayor = notas[i];
if (notas[i] < numeroMenor) numeroMenor = notas[i];
}

int numeroMayorCont = 0;
int numeroMenorCont = 0;
for (int i=0; i<10; i++)
{
if (notas[i] == numeroMayor) numeroMayorCont++;
if (notas[i] == numeroMenor) numeroMenorCont++;
}

System.out.print("El mayor número es " + numeroMayor + " y se repite " +


numeroMayorCont + " veces y el número más pequeño es " + numeroMenor + " que se
repite " + numeroMenorCont + " veces");

sc.close();

}
}

------------------------------------------------------------------

EJERCICIO 3 DEL TEMA 4

También podría gustarte