convert code python to java code example

Example 1: python to java converter

try jython, Refer: https://www.jython.org

Example 2: convert code python to java

def BitmapHoles(strArr):
    bitmap = {}
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            bitmap[(i,j)] = int(strArr[i][j])
    
    hole_count = 0
    hole = set()
    checked = set()
    flag = True
    
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            stack = [(i,j)]
            while stack:
                coords = stack.pop()
                if coords not in checked:
                    checked.add(coords)
                    if bitmap[coords] == 0 and coords not in hole:
                        hole.add(coords)
                        if flag == True:
                            hole_count += 1
                            flag = False
                        if coords[0] - 1 >= 0 and (coords[0]-1,coords[1]) not in checked:
                            stack.append((coords[0]-1,coords[1]))
                        if coords[0] + 1 < len(strArr) and (coords[0]+1,coords[1]) not in checked:
                            stack.append((coords[0]+1,coords[1]))
                        if coords[1] - 1 >= 0 and (coords[0],coords[1]-1) not in checked:
                            stack.append((coords[0],coords[1]-1))
                        if coords[1] + 1 < len(strArr[coords[0]]) and (coords[0],coords[1]+1) not in checked:
                            stack.append((coords[0],coords[1]+1))
            flag = True
            
    return hole_count

Example 3: convert code python to java

s=input()
l=[]
s1='aeiou'
sum1=0
def snm(sum1):
    t=0
    while(sum1>0 or t>9):
        if(sum1==0):
            sum1=t
            t=0
        t=t+sum1%10
        sum1=sum1//10
    return t
    
for i in range(len(s)):
    if s[i] in s1:
        l.append(i)
for j in range(len(l)):
    k=l[j]*5
    sum1=0
    for h in range(1,k+1,2):
        sum1=sum1+h
    print(snm(sum1))

Example 4: convert code python to java

#include 
using namespace std;
 
int main()
{
  int m,ans=INT_MAX,I=-1,J=-1;
  cin>>m;
  vector> mat(m,vector());
  cin.ignore();
  for(int i=0;i>w;
      if(w=="") break;
      mat[i].push_back(stoi(w));
    }
  }
  int n=mat[0].size();
  vector> Ans1(m,vector(n,1));
  vector> Ans2(m,vector(n,1));
  vector> Ans3(m,vector(n,1));
  vector> Ans4(m,vector(n,1));
 
  for(int i=0;i=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans2[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans3[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans3[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
  }
  if(I==-1)cout<<-1;
  else cout<

Example 5: convert code python to java

#include 
using namespace std;
 
int main()
{
  int m,ans=INT_MAX,I=-1,J=-1;
  cin>>m;
  vector> mat(m,vector());
  cin.ignore();
  for(int i=0;i>w;
      if(w=="") break;
      mat[i].push_back(stoi(w));
    }
  }
  int n=mat[0].size();
  vector> Ans1(m,vector(n,1));
  vector> Ans2(m,vector(n,1));
  vector> Ans3(m,vector(n,1));
  vector> Ans4(m,vector(n,1));
 
  for(int i=0;i=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans2[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans3[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
    if(Ans3[i][j]>=4 && ans>mat[i][j])
    {ans=mat[i][j];I=i;J=j;}
  }
  if(I==-1)cout<<-1;
  else cout<

Example 6: convert code python to java

def BitmapHoles(strArr):
    bitmap = {}
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            bitmap[(i,j)] = int(strArr[i][j])
    
    hole_count = 0
    hole = set()
    checked = set()
    flag = True
    
    for i in range(len(strArr)):
        for j in range(len(strArr[i])):
            stack = [(i,j)]
            while stack:
                coords = stack.pop()
                if coords not in checked:
                    checked.add(coords)
                    if bitmap[coords] == 0 and coords not in hole:
                        hole.add(coords)
                        if flag == True:
                            hole_count += 1
                            flag = False
                        if coords[0] - 1 >= 0 and (coords[0]-1,coords[1]) not in checked:
                            stack.append((coords[0]-1,coords[1]))
                        if coords[0] + 1 < len(strArr) and (coords[0]+1,coords[1]) not in checked:
                            stack.append((coords[0]+1,coords[1]))
                        if coords[1] - 1 >= 0 and (coords[0],coords[1]-1) not in checked:
                            stack.append((coords[0],coords[1]-1))
                        if coords[1] + 1 < len(strArr[coords[0]]) and (coords[0],coords[1]+1) not in checked:
                            stack.append((coords[0],coords[1]+1))
            flag = True
            
    return hole_count

Tags:

Misc Example