Ejemplo 1: convertidor de python a java
try jython, Refer: https://www.jython.org
Ejemplo 2: convertidor de Java a Python
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Ingresa un numero para calcular su factorial: ");
int num = sc.nextInt();
System.out.println("Factorial de " + num + " es: " + factorial(num));
}
private static int factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
Ejemplo 3: convertidor de Java a Python
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Ingresa un numero para calcular su factorial: ");
int num = sc.nextInt();
System.out.println("Factorial de " + num + " es: " + factorial(num));
}
private static int factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
Ejemplo 4: convertidor de java a python
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Ingresa un numero para calcular su factorial: ");
int num = sc.nextInt();
System.out.println("Factorial de " + num + " es: " + factorial(num));
}
private static int factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
Ejemplo 5: convertidor de Java a Python
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Ingresa un numero para calcular su factorial: ");
int num = sc.nextInt();
System.out.println("Factorial de " + num + " es: " + factorial(num));
}
private static int factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
Ejemplo 6: convertidor de python a java
def SeatingStudents(arr):
K = arr[0]
occupied = arr[1:]
rows = int(K/2)
seats = []
x = 0
for i in range(rows):
seats.append([])
for j in range(2):
if((x+1) in occupied):
full_seat = True
else:
full_seat = False
seats[i].append(str(full_seat))
x+=1
seating = 0
for i in range(rows-1):
if((seats[i][0] == str(False)) and (seats[i][1] == str(False))):
seating+=1
if((seats[i][0] == str(False)) and (seats[i+1][0] == str(False))):
seating+=1
if((seats[i][1] == str(False)) and (seats[i + 1][1] == str(False))):
seating+=1
if((seats[rows - 1][0] == str(False)) and (seats[rows - 1][1] == str(False))):
seating+=1
return seating
print(SeatingStudents([12, 2, 6, 7, 11]))
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)