Académique Documents
Professionnel Documents
Culture Documents
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);
}
}
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.
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)));
}
}
}
}
import java.io.*;
public class ejercicio4 {
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 {
//procesos
P=2*(L1+L2);
A=(L1*L2) /2;
D=Math.pow((Math.pow(L1,2) +Math.pow(L2,2)),0.5);
}
}
13. ejercicio calcular el cuadrado de un nmero.
import java.io. *;
cua=num*num;
//Resultados
}
}
14. ejercicio calcular el rea del tringulo.
import java.io. *;
public class ejercicio1 {
int base,altura;
double Area;
Area=(base*altura) /2;
import java.util.*;
public class elevarFOR {
}
System.out.println("total= "+tot);
}
}
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(); } } }
package mayor_menor;
import javax.swing.JOptionPane;
public class Main {
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
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
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
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
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;
{
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)