Vous êtes sur la page 1sur 14

1.

Programa Java que lea dos nmeros enteros por teclado y los muestre por
pantalla.
import java.util.*;
public class Main {
public static void main(String[] args){
//declaracin de variables
int n1, n2;
Scanner sc = new Scanner(System.in);
//leer el primer nmero
System.out.println("Introduce un nmero entero: ");
n1 = sc.nextInt(); //lee un entero por teclado
//leer el segundo nmero
System.out.println("Introduce otro nmero entero: ");
n2 = sc.nextInt(); //lee un entero por teclado
//mostrar resultado
System.out.println("Ha introducido los nmeros: " + n1 +
" y " + n2);

}
}

2.Programa Java que lea un nombre y muestre por pantalla:


Buenos dias christian
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String cadena;
System.out.println("christian: ");
cadena = sc.nextLine();
System.out.println("Buenos Das " + cadena);
}
}

3. Escribe un programa Java que lee un nmero entero por teclado y obtiene y
muestra por pantalla el doble y el triple de ese nmero.

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numero;
System.out.println("Introduce un nmero entero:");
numero = sc.nextInt();
System.out.println("Nmero introducido: " +
numero);
System.out.println("Doble de " + numero + " -> "+
2*numero);
System.out.println("Triple de " + numero + " -> "+
3*numero);
}
}
4. Pedir los coeficientes de una ecuacin se 2 grado, y muestre sus soluciones
reales. Si no existen, debe indicarlo.

public static void main(String[] args)


{
double a,b,c; // coeficientes ax^2+bx+c=0
double x1,x2,d; // soluciones y determinante
System.out.println("Introduzca primer coeficiente (a):");
a=Entrada.entero();
System.out.println("Introduzca segundo coeficiente: (b):");
b=Entrada.entero();
System.out.println("Introduzca tercer coeficiente: (c):");
c=Entrada.entero();
// calculamos el determinante
d=((b*b)-4*a*c);
if(d<0)
System.out.println("No existen soluciones reales");
Else
{
// queda confirmar que a sea distinto de 0.
// si a=0 nos encontramos una divisin por cero.
x1=(-b+Math.sqrt(d))/(2*a);
x2=(-b-Math.sqrt(d))/(2*a);
System.out.println("Solucin: " + x1);
System.out.println("Solucin: " + x2);
}
}
}

5. pedir el radio de un crculo y calcular su rea. A=PI*r^2


public class Main
{
public static void main(String[] args)
{
double a,r; // rea y radio
System.out.print("Introduce el radio de un circulo: ");
r=Entrada.real();
a=Math.PI*(r*r); // para elevar al cuadrado otra opcin es:
Math.pow (r, 2) System.out.println("El rea de
una circunferencia de radio " + r+ " es: " + a);
}
}

6. Hallar A+B-C+100
Cdigo:
class JavaAritmetica1
{
public static void main (String mago [])
{
int A, B, C;
System.out.print ("Inserte A: ");
A = Leer.datoInt ();
System.out.print ("Inserte B: ");
B = Leer.datoInt ();
System.out.print ("Inserte C: ");
C = Leer.datoInt ();
System.out.println ("\n" + A + " + " + " " + B + " - " + C + " + " + 100 + "
= " + (A + B - C + 100));
}
}

7. Hallar (a-b)(a+b)
Cdigo:
class JavaAritmetica2
{
public static void main (String elMago [])
{
int a, b;
System.out.print ("Inserte valor a: ");
a = Leer.datoInt ();
System.out.print ("Inserte valor b: ");
b = Leer.datoInt ();
System.out.println ("(" + a + "-" + b + ") " + "(" + a + "+" + b + ") " + "=
" + ((a - b) * (a + b)));
}
}

8. Leer un numeo de tres dgitos y sumarlos


Cdigo:
class JavaAritmetica3
{
public static void main (String elMago [])
{
int numero, sumDig = 0;
System.out.print ("Inserte numero de tres digitos: ");
numero = Leer.datoInt ();
if (numero <= 100)
System.out.println ("ERROR: El numero no tiene 3 digitos");
else
{
int aux = numero; //en aux salvamos numero
while (numero != 0)
{
sumDig = sumDig + (numero % 10); //sumamos a sumDig el ultimo digito de
numero
numero = numero / 10; //eliminamos el ultimo digito de numero
}
System.out.println ("La suma de los digitos de " + aux + " es: " +
sumDig);
}
}
}

9. Dado un numero entero, determinar si es positivo, negativo o nulo


Cdigo:
class JavaAritmetica5
{
public static void main (String args [])
{
int numero;
System.out.print ("Inserte un numero: ");
numero = Leer.datoInt ();
if (numero == 0)
System.out.println ("El numero " + numero + " es NULO");
else
{
if (numero < 0)
System.out.println ("El numero " + numero + " es NEGATIVO");
else
System.out.println ("El numero " + numero + " es POSITIVO");
}

}
}

10. Dados seis nmero determinar el menor de ellos


Cdigo:
class JavaAritmetica6
{
public static void main (String args [])
{
int a, b, c, d, e, f;
System.out.print ("Inserte num.1: ");
a = Leer.datoInt ();
System.out.print ("Inserte num.2: ");
b = Leer.datoInt ();
System.out.print ("Inserte num.3: ");
c = Leer.datoInt ();
System.out.print ("Inserte num.4: ");
d = Leer.datoInt ();
System.out.print ("Inserte num.5: ");
e = Leer.datoInt ();
System.out.print ("Inserte num.6: ");
f = Leer.datoInt ();
int menor = a;
if (b < menor)
menor = b;
if (c < menor)
menor = c;
if (d < menor)
menor = d;
if (e < menor)
menor = e;
if (f < menor)
menor = f;
System.out.println ("\nEl menor de:" + a + "," + b + "," + c + "," + d + ","
+ e + "," + f + ",");
System.out.println ("Es: " + menor);
}
}

11. calcular la suma la resta y la multiplicacin de dos nmeros.

import java.io.*;
public class ejercicio4 {

public static void main(String[] args) throws


IOException{
BufferedReader br = new BufferedReader (new
InputStreamReader(System.in));
int n1, n2, S, R, M;
System.out.print("ingrese primer numero:");
n1=Integer.parseInt(br.readLine());
System.out.print("ingrese segundo numero:");
n2=Integer.parseInt(br.readLine());

S=n1+n2;
R=n1-n2;
M=n1*n2;
System.out.println("la suma de " + n1 + " + " + n2
+ " es: " + S);
System.out.println("la resta de " + n1 + " -" + n2
+ "es: " + R);
System.out.println("la multiplicacion de " + n1 +
" * " + n2 + " es: " + M);

}
}
12. calcular el rea permetro y diagonal d un rectngulo.

import java.io.*;
public class ejercicio5 {

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


{
BufferedReader sal = new BufferedReader (new
InputStreamReader(System.in));
double L1,L2,P,A,D;
System.out.print("ingrese lado 1:");
L1=Double.parseDouble(sal.readLine());
System.out.print("ingrese lado 2:");
L2=Double.parseDouble(sal.readLine());

//procesos
P=2*(L1+L2);
A=(L1*L2) /2;
D=Math.pow((Math.pow(L1,2) +Math.pow(L2,2)),0.5);

System.out.println("el perimetro es: " + P);


System.out.println("el area es: " + A);
System.out.println("la diagonal es: " + D);

}
}
13. ejercicio calcular el cuadrado de un nmero.

import java.io. *;

public class ejercicio2 {

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


{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
//Declaracion de variables
int num, cua;
//Ingreso de datos

System.out.print("ingrese un numero: ");


num = Integer.parseInt(br.readLine());
//Proceso

cua=num*num;

//Resultados

System.out.print("el cuadrado del nmero es: " + cua);

}
}
14. ejercicio calcular el rea del tringulo.

import java.io. *;
public class ejercicio1 {

public static void main(String [] args) throws


IOException {

BufferedReader br = new BufferedReader (new


InputStreamReader(System.in));

int base,altura;
double Area;

System.out.print(" ingrese la base: ");


base = Integer.parseInt(br.readLine());
System.out.print("ingrese la altura: ");
altura = Integer.parseInt(br.readLine());

Area=(base*altura) /2;

System.out.print(" el rea del tringulo es: " + Area);


}
}

15. Programa que eleve un nmero a n potencia usando for.

import java.util.*;
public class elevarFOR {

public static void main(String[] args) {


Scanner teclado=new Scanner(System.in);
int i=1,tot=0,num,ele;
System.out.print("numero a elevar: ");
num=teclado.nextInt();
System.out.print("elevar a la: ");
ele=teclado.nextInt();
tot=num;
for(i=2;i<=ele;i++)
{
tot*=num;

}
System.out.println("total= "+tot);

}
}

16. Programa para elevar un nmero a n potencia usando while

import java.util.*;
public class elevarWHILE {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
int i=2,tot=0,num,ele;
System.out.print("numero a elevar: ");
num=teclado.nextInt();
System.out.print("elevar a la: ");
ele=teclado.nextInt();
tot= (int) Math.pow(num,ele);
System.out.println("total= "+tot);

}
}
17. Programa que imprima las 10 tablas de multiplicar
public class Main
{
public static void main(String[] args)
{
int i,j,r;
for(i=1;i<=10;i++)
{
for(j=1;j<=8;j++)
{
r=i*j;
System.out.println(i+" * "+j+" = "+r);
}
System.out.println(); } } }

18. Programa que realiza la tabla de multiplicar de cualquier digito

public static void main(String[] args) {


int i,j,r,tabla=0;
tabla=Integer.parseInt(JOptionPane.showInputDialog("QUE
TABLA DESEA REALIZAR? :"));
for(i=1;i<=10;i++)
{
r=i*tabla;
System.out.println(tabla+" * "+i+" = "+r);
}
}
}
19. Programa que calcule el mayor y menor de n nmeros

package mayor_menor;
import javax.swing.JOptionPane;
public class Main {

public static void main(String[] args) {


// TODO code application logic here
int cant,num,mayor=0,menor=0,i;
cant=Integer.parseInt(JOptionPane.showInputDialog("ingre
se repeticiones:"));
for(i=1;i<=cant;i++)
{
num=Integer.parseInt(JOptionPane.showInputDialog("ing
rese numero:"));
if(i==1){
mayor=num;
menor=num;
}
if(num<menor)
menor=num;
if(num>mayor)
mayor=num;
}
System.out.println("mayor= "+mayor);
System.out.println("menor= "+menor);
}}
20. suma
import java.io.*;

public class POTENCIA


{
public static void main (String[]args) throws IOException
{
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader flujoE = new BufferedReader (isr);

String sdato;
int a;
int b;
int c;
System.out.print("INGRESE EL 1 NUMERO:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
a=Integer.parseInt(sdato);//convierte el dato a entero

System.out.print("INGRESE EL 2 NUMERO:");
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
b=Integer.parseInt(sdato);//convierte el dato a entero

c=a+b;//operacion

System.out.print("LA SUMA ES:" + c);//IMPRIMIR EL DATO


}
}

21. potencia
import java.io.*;
import java.lang.Math;//esto es para potencia raiz etc
public class POTENCIA
{
public static void main (String[]args) throws IOException
{
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader flujoE = new BufferedReader (isr);

String sdato;
double a, b, c;
System.out.print("INGRESE LA BASE:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
a=Double.parseDouble(sdato);//convierte el dato a entero

System.out.print("INGRESE EL EXPONENTE:");
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
b=Double.parseDouble(sdato);//convierte el dato a entero

c=Math.pow(a,b); //Math.pow se para potencia


System.out.print("LA RESULTADO ES:" + c);//IMPRIMIR EL
DATO
}
22. Raz
import java.io.*;
import java.lang.Math;//esto es para potencia raiz etc
public class POTENCIA
{
public static void main (String[]args) throws IOException
{
InputStreamReader isr = new InputStreamReader
(System.in);
BufferedReader flujoE = new BufferedReader (isr);

String sdato;

double a, b, c;
System.out.print("ingrese el numero:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
a=Double.parseDouble(sdato);//convierte el dato a
entero

//System.out.print("INGRESE EL EXPONENTE:");
//sdato=flujoE.readLine();//LEER EL DATO DEL
PROGRAMA
//b=Double.parseDouble(sdato);//convierte el dato a
entero

c=Math.sqrt(a); //Math.pow se para potencia


System.out.print("LA RAIZ ES:" + c);//IMPRIMIR EL
DATO
}
}
23. Concatenar
public static void main (String[]args) throws IOException
{
InputStreamReader isr = new InputStreamReader
(System.in);
BufferedReader flujoE = new BufferedReader (isr);

String sdato;

String a, b, c;
System.out.print("ingrese el numero y/o
palabra:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
a=sdato;//convierte el dato a entero

System.out.print("INGRESE EL 2 numero y/o palabra


:");
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
b=sdato;//convierte el dato a entero

c= a+b ; //Math.pow se para potencia


System.out.print("LA suma ES:" + c);//IMPRIMIR EL
DATO

IF ELSE
24. Valor absoluto
import java.io.*;
public class POTENCIA
{
public static void main (String[]args) throws IOException
{
InputStreamReader isr = new InputStreamReader
(System.in);
BufferedReader flujoE = new BufferedReader (isr);

String sdato;
int a, b;
System.out.print("ingrese el numero:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
a=Integer.parseInt(sdato);//convierte el dato a
entero

if(a<0)
b= -1*a;
else
b= a;

System.out.print("el valor absoluto es:" +


b);//IMPRIMIR EL DATO
}
}
25. Mayor de dos numeros
import java.io.*;
public class POTENCIA

{
public static void main (String[]args) throws IOException
{
InputStreamReader isr = new InputStreamReader
(System.in);
BufferedReader flujoE = new BufferedReader (isr);

String sdato;

int a, b;
System.out.print("ingrese el numero:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
a=Integer.parseInt(sdato);//convierte el dato a
entero

System.out.print("ingrese el numero:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
b=Integer.parseInt(sdato);
if(a<b)

System.out.print("el valor absoluto es:" + a);


else

System.out.print("el valor absoluto es:" +


b);//IMPRIMIR EL DATO
}
}
26. Mayor de 3 nmeros
import java.io.*;
public class POTENCIA
{
public static void main (String[]args) throws IOException
{
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader flujoE = new BufferedReader (isr);
String sdato;
int a, b, c, mayor;
System.out.print("ingrese 1 numero:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
a=Integer.parseInt(sdato);//convierte el dato entero
System.out.print("ingrese 2 numero:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
b=Integer.parseInt(sdato);
System.out.print("ingrese 3 numero:");//IMPRIMIR
sdato=flujoE.readLine();//LEER EL DATO DEL PROGRAMA
c=Integer.parseInt(sdato);
if(a>b)
if (a>c)
mayor=a;
else
mayor=c;
else
if(b>c)
mayor=b;
else
mayor=c;
System.out.print("el numero mayor es:" + mayor);//IMPRIMIR EL DATO
}
}

Vous aimerez peut-être aussi