Example 1: python to java converter
try jython, Refer: https://www.jython.org
Example 2: python to java converter
def getUmbrellas(requirement, sizes):
for i in sizes:
if i > requirement:
pass
else:
q = requirement / i
r = requirement % i
if r == 0:
return q
if r in sizes:
return q + 1
return -1
Example 3: python to java converter
import sys
import math
width = int(input())
height = int(input())
players = int(input())
class Player:
def __init__(self, x, y):
self.x = x
self.y = y
DIR = {'UP' : 'C', 'RIGHT' : 'A', 'DOWN' : 'D', 'LEFT' : 'E', 'STAY' : 'B'}
grid = [['?' for x in range(width)] for y in range(height)]
enemies = [Player(-1,-1) for e in range(players-1)]
player = Player(-1,-1)
def enemyAtPos(x, y):
for e in enemies:
if x == e.x and y == e.y:
return True
return False
def getPossibleMoves(x, y):
possibleMoves = []
if grid[(y-1)%height][x] != '#':
if not enemyAtPos(x, y-1) and not enemyAtPos(x, y-2) and not enemyAtPos(x-1, y-1) and not enemyAtPos(x+1, y-1):
possibleMoves.append([x, (y-1)%height])
if grid[y][(x+1)%width] != '#':
if not enemyAtPos(x+1, y) and not enemyAtPos(x+2, y) and not enemyAtPos(x+1, y-1) and not enemyAtPos(x+1, y+1):
possibleMoves.append([(x+1)%width, y])
if grid[(y+1)%height][x] != '#':
if not enemyAtPos(x, y+1) and not enemyAtPos(x, y+2) and not enemyAtPos(x-1, y+1) and not enemyAtPos(x+1, y+1):
possibleMoves.append([x, (y+1)%height])
if grid[y][(x-1)%width] != '#':
if not enemyAtPos(x-1, y) and not enemyAtPos(x-2, y) and not enemyAtPos(x-1, y-1) and not enemyAtPos(x-1, y+1):
possibleMoves.append([(x-1)%width, y])
return possibleMoves
Example 4: python to java converter
array=list(map(int,input().split(",")))
array=sorted(array)
j=[]
j.append(array[0])
j.append(array[1])
for i in range(2,len(array)):
if j[i-1]+j[i-2] in array:
j.append(j[i-1]+j[i-2])
else:
break
print(j)
Example 5: python to java converter
array=list(map(int,input().split(",")))
array=sorted(array)
j=[]
j.append(array[0])
j.append(array[1])
for i in range(2,len(array)):
if j[i-1]+j[i-2] in array:
j.append(j[i-1]+j[i-2])
else:
break
print(j)
Example 6: python to java converter
import math as mt
def authentication(arr, n, m):
t=0
while (1):
items = 0
for i in range(n):
items += (t//arr[i])
if(items>=m):
return t+10
t+=1
arr=list(map(int,input().split()))
n=len(arr)
m=30
print(authentication(arr, n, m))
Example 7: python to java converter
import math as mt
def authentication(arr, n, m):
t=0
while (1):
items = 0
for i in range(n):
items += (t//arr[i])
if(items>=m):
return t+10
t+=1
arr=list(map(int,input().split()))
n=len(arr)
m=30
print(authentication(arr, n, m))
Example 8: python to java converter
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]))
Example 9: python to java converter
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]))
Example 10: python to java converter
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]))