You are on page 1of 3

//1.

NUMEROS PARES Y DIVISIBLES POR TRES

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class parydivisible {

public static void main(String[] args) throws IOException {


BufferedReader br = new BufferedReader (new InputStreamReader
(System.in));

int cant, num, pares=0;

System.out.println ("Cuantos numeros desea ingresar: ");

String nu = br.readLine ();

int n = Integer.parseInt (nu);

System.out.println();

int contador=0;

for(int i=1; i<=n; i++){

System.out.print("Ingresar numero " + i + " de " + n + ": ");

num = (new Scanner(System.in)).nextInt();

if(num % 2 == 0)

pares++;

if(num % 3 == 0)

contador++;
}
System.out.println("\nHay un total de "+contador+ " numeros divisibles por
tres");

System.out.println("\nCantidad de numeros pares: " + pares);


}
}

-----------------------------------------------------------------------------------
-----------------------------------
//2.VECTORES IGUALES O DIFERENTES

import java.util.Scanner;

public class vectoresiguales {

public static void main(String args[])


{
int tamA, tamB,i,comparacion = 0;
int A[], B[];
Scanner sc = new Scanner(System.in);
System.out.println("Ingrese el tama�o del vector A: ");
tamA=sc.nextInt();
System.out.println("Ingrese el tama�o del vector B: ");
tamB=sc.nextInt();

A = new int[tamA];
B = new int[tamB];

for(i=0;i<tamA;i++)

{
System.out.println("Digite el digito " + i + " de " + tamA + " del vector
A");
A[i]=sc.nextInt();
}
for(i=0;i<tamA;i++)

{
System.out.println("Digite el digito " + i + " de " + tamA + " del vector
B");
B[i]=sc.nextInt();
}
for(i = 0; i < tamA;i++)
{
if(A[i] == B[i])
{
comparacion++;

}
if(comparacion == tamA)
{
System.out.println("Los dos vectores son iguales :)");

}
if(comparacion < tamA)
{
System.out.println("Los dos vectores son distintos :(");

-----------------------------------------------------------------------------------
---------------------------------------
//3.CUANTAS VECES APARECE UN NUMERO X

import java.util.Scanner;

public class contarnumero {


public static void main(String[] args) {
Scanner linea = new Scanner(System.in);
long n;
System.out.print("Digite vector:\t");
n = linea.nextLong();
String num = String.valueOf(n);
for(int d = 0; d < 10; d++) {
int rep = 0;
for(int i = 0; i < num.length(); i++) {
if(Integer.valueOf(String.valueOf(num.charAt(i))) == d) {
rep++;
}
}
if(rep > 0) {
System.out.println(
String.format("El n�mero %d aparece %d %s",
d, rep, (rep == 1 ? "vez" : "veces"))
);
}
}
}
}

You might also like