0% encontró este documento útil (0 votos)
33 vistas6 páginas

Programa en C# para Contar Vocales y Más

El documento contiene varios ejercicios de programación en Java. En particular, incluye ejemplos de cómo contar vocales en una frase, comparar números, imprimir números del 1 al 100 usando bucles, leer números del usuario y realizar cálculos con ellos.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
33 vistas6 páginas

Programa en C# para Contar Vocales y Más

El documento contiene varios ejercicios de programación en Java. En particular, incluye ejemplos de cómo contar vocales en una frase, comparar números, imprimir números del 1 al 100 usando bucles, leer números del usuario y realizar cálculos con ellos.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd

PRACTICA 2

ESCRIBA UN PROGRAMA QUE LEA UNA ORACION Y CUENTE


CUANTAS VOCALES TIENE
public static int vocalfrase(string f char v)
{
int p=0
for(int 1=0; i < ([Link]); int++)
{
if (f []i==v) {p++ }
}
return p;
}

static void Main(string[] args)


{
String frase;
[Link]("intro la frase");
frase = [Link]();
[Link]("la frase tine {0} de vocales a "
vocalfrase(frase, a));
[Link]();

DECLARA 2 VARIABLES NUMÉRICAS (CON EL VALOR QUE DESEES), HE


INDICA CUAL ES MAYOR DE LOS DOS. SI SON IGUALES INDICARLO
TAMBIÉN. VES CAMBIANDO LOS VALORES PARA COMPROBAR QUE
FUNCIONA
int numero1 = 54;
float numero2 = 564.6f;

// IF encadenados
if (numero1 == numero2) {
[Link]("Son iguales");
} else if (numero1 > numero2) {
[Link]("Número 1 es mayor");
} else if (numero2 > numero1) {
[Link]("Número 2 es mayor");
}

if (numero1 == numero2) {
[Link]("Son iguales");
} else {
if (numero1 > numero2) {
[Link]("Número 1 es
mayor");
} else if (numero2 > numero1) {
[Link]("Número 2 es
mayor");
}
}
if (numero1 != numero2) {
if (numero1 > numero2) {
[Link]("Número 1 es
mayor");
} else if (numero2 > numero1) {
[Link]("Número 2 es
mayor");
}
} else {
[Link]("Son iguales");
}

}
[Link]()

DECLARA UN STRING QUE CONTENGA TU NOMBRE, DESPUÉS


MUESTRA UN MENSAJE DE BIENVENIDA POR CONSOLA. POR
EJEMPLO: SI INTRODUZCO “FERNANDO”, ME APAREZCA
“BIENVENIDO FERNANDO”
public static void main(String[] args) {

String nombre;
[Link]("Hola " + nombre);

String nombre2 = new String("-");


[Link]("Hola " + nombre2);

}
}
[Link]();

LEE UN NÚMERO POR TECLADO E INDICA SI ES DIVISIBLE ENTRE 2


(RESTO = 0). SI NO LO ES, TAMBIÉN DEBEMOS INDICARLO
public static void main(String[] args)
{

Scanner sc = new Scanner([Link]);

// Manera 1
float numero = [Link]();

// Manera 2
// String linea = [Link]();
// int numero = [Link](linea);

if (numero % 2 == 0)
{
[Link]("Sí es divisible entre dos");
}
else
{
[Link]("NO es divisible entre dos");
}

// Hay que cerrar todo lo que trabaje con ficheros o consolas


[Link]();

[Link]();

LEE UN NÚMERO POR TECLADO QUE PIDA EL PRECIO DE UN


PRODUCTO (PUEDE TENER DECIMALES) Y CALCULE EL PRECIO FINAL
CON IVA. EL IVA SERA UNA CONSTANTE QUE SERA DEL 21%
public static void main(String[] args)
{

Final float IVA = 1.21f;

Scanner sc = new Scanner([Link]);


Double precio = [Link]();

precio = precio * IVA;

[Link]("El precio introducido más el IVA es : " +


[Link](precio));

[Link]();
[Link]();

MUESTRA LOS NÚMEROS DEL 1 AL 100 (AMBOS INCLUIDOS). USA UN


BUCLE WHILE
public static void main(String[] args)
{

int i = 1;
while (i <= 100)
{
[Link](i);
i++;
}

i = 1;
do
{
[Link](i);
i++;
} while (i <= 100);

i = 1;
for (; i <= 100;)
{
[Link](i);
i++;
}

for (i = 1; i <= 100; i++)


{
[Link](i);
}
[Link]();

HAZ EL MISMO EJERCICIO ANTERIOR CON UN BUCLE FOR

MUESTRA LOS NÚMEROS DEL 1 AL 100 (AMBOS INCLUIDOS)


DIVISIBLES ENTRE 2 Y 3. UTILIZA EL BUCLE QUE DESEES
public static void main(String[] args)
{

for (int i = 1; i <= 100; i++)


{
// Método 1
if (i % 2 == 0)
{
if (i % 3 == 0)
{
[Link](i + " es divisible por 2 y 3");
}
}
// Método 2
if ((i % 2 == 0) && (i % 3 == 0))
{
[Link](i + " es divisible por 2 y 3");
}
}

int i = 1;
while (i <= 100)
{
if ((i % 2 == 0) && (i % 3 == 0))
{
[Link](i + " es divisible por 2 y 3");
}
i++;
[Link]();

LEE UN NÚMERO POR TECLADO Y COMPRUEBA QUE ESTE NUMERO ES


MAYOR O IGUAL QUE CERO, SI NO LO ES LO VOLVERÁ A PEDIR (DO
WHILE), DESPUÉS MUESTRA ESE NÚMERO POR CONSOLA
public static void main(String[] args)
{

int numero = -1;


while (numero < 0)
{
[Link]("Introduzca un número");
try
{
numero = [Link]([Link]());
if (numero == 0) throw new Exception();
}
catch (NumberFormatException e)
{
[Link]("Tienes que introducir números");
numero = -1;
}
catch (Exception e)
{
[Link]("Tienes que introducir números positivos
mayores que cero");
numero = -1;
}
}
[Link]("El número introducido es " + numero);

[Link]();

REALIZA UNA APLICACIÓN QUE NOS PIDA UN NÚMERO DE VENTAS A


INTRODUCIR, DESPUÉS NOS PEDIRÁ TANTAS VENTAS POR TECLADO
COMO NÚMERO DE VENTAS SE HAYAN INDICADO. AL FINAL
MOSTRARA LA SUMA DE TODAS LAS VENTAS. PIENSA QUE ES LO QUE
SE REPITE Y LO QUE NO
public static void main(String[] args)
{

Scanner sc = new Scanner([Link]);

[Link]("¿Cuántos tipos de artículo?");


int tiposArticulos = [Link]();

int total = 0;
for (int i = 1; i <= tiposArticulos; i++)
{
[Link]("¿Cuántos artículos del tipo " + i + "?");
total += [Link]();
}

[Link]("Total artículos : " + total);

[Link]();

DECLARA DOS VARIABLES NUMÉRICAS (CON EL VALOR QUE DESEES),


MUESTRA POR CONSOLA LA SUMA, RESTA, MULTIPLICACIÓN,
DIVISIÓN Y MÓDULO (RESTO DE LA DIVISIÓN)
static void Main(string[] args)
{
int numero1 = 13;
int numero2 = 24;

int suma = numero1 + numero2;


[Link]("la suma es " + numero1 + numero2);
[Link]("la suma es " + (numero1 + numero2));
[Link](suma);

[Link]("la resta es " + (numero1 - numero2));


[Link]();

ESCRIBA UN PROGRAMA QUE LEA 5NÚMEROS DESDE TECLADO Y


PRESENTE LA SUMATORIA DE LOS MISMOS. HACER USO DE LA
ESTRUCTURA REPETITIVA WHILE
public static void main(String[] ar)
{
int x;
x = 1;
while (x <= 100)
{
[Link](x);
[Link](" - ");
x = x + 1;
[Link]();

También podría gustarte