Sie sind auf Seite 1von 8

10.

-Evaluar para n valores aleatorios de x


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

package evaluarlafuncion;
import java.util.Scanner;
public class EvaluarLaFuncion
{
int n;
double f;
double x;
void evaluar()
{
Scanner obj=new Scanner(System.in);
System.out.print("Ingrese numeros de valores: ");
n= obj.nextInt();
for(int t=0; t<n; t++)
{
x= ((Math.random())*8)-4;
f= Math.pow(Math.sqrt(2*Math.PI),-1)*Math.exp(Math.pow(x-3,2));
System.out.println("x= "+x);
System.out.println("f("+x+")= "+f);
}
}
public static void main(String[] args)
{
EvaluarLaFuncion obj1=new EvaluarLaFuncion();
obj1.evaluar();
}
}
run:
Ingrese numeros de valores: 10
x= 0.45485376646518016
f(0.45485376646518016)= 259.51923336471606
x= -3.8462922646315345
f(-3.8462922646315345)= 9.058127968052752E19
x= 1.294196031120486
f(1.294196031120486)= 7.321598270032031
x= 1.7368498049342742
f(1.7368498049342742)= 1.9671973839602868
x= 1.6441106015198619
f(1.6441106015198619)= 2.5080298577559206
x= 3.7918246278247763
f(3.7918246278247763)= 0.7468041636753265

x= -1.2759966719325906
f(-1.2759966719325906)= 3.480282101727157E7
x= -1.6498683984724174
f(-1.6498683984724174)= 9.792892289507966E8
x= -1.7135580365949847
f(-1.7135580365949847)= 1.7778859575926728E9
x= -0.8094804910117919
f(-0.8094804910117919)= 800669.1369199556

6.-Lee 4 numeros enteros e imprime la suma como una fraccion


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

packagesumarfracion;
importjava.util.Scanner;
publicclassSumarFracion //Esta aplicacion nos lee 4 numerosenteros e imprime
//la suma como una funcion
{
int a;
int b;
int c;
int d;
voidsumarFracion()
{
Scanner obj = new Scanner(System.in);
System.out.println("Ingrese 4 numeros enteros: ");
System.out.print("a= ");
a= obj.nextInt();
System.out.print("b= ");
b= obj.nextInt();
System.out.print("c= ");
c= obj.nextInt();
System.out.print("d= ");
d= obj.nextInt();
System.out.println("La suma es: \n V = "+a+"/"+b+" + "+c+"/"+d);
}
public static void main(String[] args)
{
SumarFracion obj1= new SumarFracion();
obj1.sumarFracion();
}
}
run:
Ingrese 4 numeros enteros:
a= 5
b= 2
c= 8
d= 4
La suma es:
V = 5/2 + 8/4

4.-Lee 4 numeros de tipo float e imprime la suma y el promedio


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

packagesumaypromedio;
importjava.util.Scanner;
publicclassSumayPromedio//esta aplicacion nos suma y promedia
// 4 numeros de tipo float
{
float S;
float P;
float a;
float b;
float c;
float d;
void leer()
{
Scanner obj= new Scanner(System.in);
System.out.println("Ingrese 4 numeros de tipo float: ");
System.out.print("a= ");
a= obj.nextFloat();
System.out.print("b= ");
b= obj.nextFloat();
System.out.print("c= ");
c= obj.nextFloat();
System.out.print("d= ");
d= obj.nextFloat();
S= a+b+c+d;
P= S/4;
System.out.println("La suma es: "+S);
System.out.println("El promrdio es: "+P);
}
public static void main(String[] args)
{
SumayPromedio obj1= new SumayPromedio();
obj1.leer();
}
}
run:
Ingrese 4 numeros de tipo float:
a= 2,56

b= 4,012
c= 8,25
d= 1,024
La suma es: 15.846001
El promrdio es: 3.9615002

9.-Evaluar funcin para N valores de X aumentados en 0.2


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

package evaluarfuncion;
import java.util.Scanner;
public class Main
{
void evluarFuncion()
{
Scanner obj= new Scanner(System.in);
System.out.println("Ingrese N :");
int N= obj.nextInt();
System.out.println("Ingrese X :");
double x= obj.nextDouble();
for(int t=0; t<N; t++)
{
double fx= 3*Math.pow(x,5) + 2*x + Math.sin(x);
System.out.println("f("+x+")= "+fx);
x= x+0.2*(t+1);
}
}
public static void main(String[] args)
{
Main obj= new Main();
obj.evluarFuncion();
}
}
run:
Ingrese N :5
Ingrese X :2
f(2.0)= 100.90929742682569
f(2.2)= 159.81745640381965
f(2.6)= 362.1567813718215
f(3.2)= 1012.9745858565726
f(4.0)= 3079.243197504692

3.-Ingrese dos caracteres en uno en minscula y otro en mayscula e imprime el valor ASCCI
(ejemplo: aA ).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

import java.io.*;
publicclassValorAscci
{
char minus=0;
char mayus=0;
publicvoid leer()
{
try
{
System.out.println("Ingrese una letra en minuscula y en mayuscula "
+ "(consecutivos): ");
minus=(char)System.in.read();
mayus=(char)System.in.read();
System.out.println("El codigo ASCCI de "+minus+" es: "+(int)minus);
System.out.println("El codigo ASCCI de "+mayus+" es: "+(int)mayus);
}
catch(IOException e){}
}
public static void main(String[] args)
{
ValorAscciobj=new ValorAscci();
obj.leer();
}
}
Ingrese una letra en minuscula y en mayuscula (consecutivos):
zZ
El codigo ASCCI de z es: 122
El codigo ASCCI de Z es: 90

Das könnte Ihnen auch gefallen