Arreglar radares de tramo
This commit is contained in:
1 parent
6ad15af53b
commit
a01c50d36c
2 files changed
+26
-12
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class RadaresDeTramo {
|
public class P112_RadaresDeTramo {
|
||||||
public static void main() {
|
public static void main() {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
int distancia = 0; // Distancia entre las cámaras (metros)
|
int distancia = 0; // Distancia entre las cámaras (metros)
|
||||||
@@ -8,11 +8,15 @@ public class RadaresDeTramo {
|
|||||||
int tiempo = 0; // Tiempo que tarda el coche en pasar entre las cámaras (segundos)
|
int tiempo = 0; // Tiempo que tarda el coche en pasar entre las cámaras (segundos)
|
||||||
|
|
||||||
while(true) { // Condición de salida después de obtener datos
|
while(true) { // Condición de salida después de obtener datos
|
||||||
System.out.print("Introduce los datos: ");
|
|
||||||
distancia = sc.nextInt();
|
distancia = sc.nextInt();
|
||||||
velPermitida = sc.nextInt();
|
velPermitida = sc.nextInt();
|
||||||
tiempo = sc.nextInt();
|
tiempo = sc.nextInt();
|
||||||
sc.nextLine(); // Limpiar stdin
|
sc.nextLine(); // Limpiar stdin
|
||||||
|
// Validar que los datos sean mayores que 0
|
||||||
|
if (distancia < 0 || velPermitida < 0 || tiempo < 0) {
|
||||||
|
System.out.println("ERROR");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// Salir del bucle
|
// Salir del bucle
|
||||||
if (distancia == 0 && velPermitida == 0 && tiempo == 0) {
|
if (distancia == 0 && velPermitida == 0 && tiempo == 0) {
|
||||||
System.out.println("SALIR");
|
System.out.println("SALIR");
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
import java.util.Scanner;
|
||||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
|
||||||
void main() {
|
|
||||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
|
||||||
// to see how IntelliJ IDEA suggests fixing it.
|
|
||||||
IO.println(String.format("Hello and welcome!"));
|
|
||||||
|
|
||||||
for (int i = 1; i <= 5; i++) {
|
void main() {
|
||||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
Scanner sc = new Scanner(System.in);
|
||||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
// Coordenadas de las esquinas opuestas
|
||||||
IO.println("i = " + i);
|
int ax, ay, bx, by;
|
||||||
|
// Longitud de lados
|
||||||
|
int l1, l2;
|
||||||
|
// Area del rectangulo
|
||||||
|
int area;
|
||||||
|
while(true) {
|
||||||
|
System.out.print("Introduce las coordenadas del rectángulo (ax ay bx by): ");
|
||||||
|
ax = sc.nextInt();
|
||||||
|
ay = sc.nextInt();
|
||||||
|
bx = sc.nextInt();
|
||||||
|
by = sc.nextInt();
|
||||||
|
// Ternario para obtener resta positiva
|
||||||
|
l1 = (ax < bx) ? bx - ax : ax - bx;
|
||||||
|
l2 = (ay < by) ? by - ay : ay - by;
|
||||||
|
area = l1 * l2;
|
||||||
|
System.out.println("El área es: " + area);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user