-
Lenguaje
Java usando Scanner
-
Descripción
Dados N valores, haga el siguiente proceso:
- Si el valor es menor que cero calcular su cubo.
- Si el valor está entre 0 y 100 calcular su cuadrado.
- Si el valor está entre 101 y 1000 calcular su raíz cuadrada.
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
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
import java.util.Scanner;
public class CuboCuadradoORaiz {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i, n;
double resultado, v;
System.out.print("Ingresa el valor de n: ");
n = in.nextInt();
in.nextLine();
for (i=1; i<=n; i++) {
System.out.print("PROCESO " + i);
System.out.print("Ingresa el valor de v: ");
v = in.nextDouble();
in.nextLine();
resultado=0;
if(v<0)
resultado=v*v*v;
if(v>=0&&v<=100)
resultado=v*v;
if(v>=101&&v<=1000)
resultado=Math.sqrt(v);
System.out.println("Valor de resultado: " + resultado);
System.out.println();
}
}
}
public class CuboCuadradoORaiz {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i, n;
double resultado, v;
System.out.print("Ingresa el valor de n: ");
n = in.nextInt();
in.nextLine();
for (i=1; i<=n; i++) {
System.out.print("PROCESO " + i);
System.out.print("Ingresa el valor de v: ");
v = in.nextDouble();
in.nextLine();
resultado=0;
if(v<0)
resultado=v*v*v;
if(v>=0&&v<=100)
resultado=v*v;
if(v>=101&&v<=1000)
resultado=Math.sqrt(v);
System.out.println("Valor de resultado: " + resultado);
System.out.println();
}
}
}