Answers for "java to python converter"

1

java to python

#include<stdio.h>
int stack[10000000]={0};
int top=-1;
 
void push(int c)
{
    stack[++top]=c;
}
 
void pop()
{
    stack[top--]=0;
}
 
int main()
{
    int N,max=0;
    int order=1;
    scanf("%d",&N);
    int arr[N];
    for(int i=0;i<N;i++)
    {
        scanf("%d",&arr[i]);
        if(max<arr[i])
        max=arr[i];
    }
    
    for(int i=0;i<N;i++)
    {
        while(top!=-1 && stack[top]==order)
        {
            order++;
            pop();
        }
        if(arr[i]==order)
        {
            order++;
          
        }
        else
        push(arr[i]);
        
    }
      while(top!=-1 && stack[top]==order)
        {
            order++;
            pop();
        }
    
    if(order==max+1)
    printf("Happy");
    else
    printf("Sad");
    
    
}
Posted by: Guest on July-18-2021
1

java to python

public class testint
	{
	    public static void main(String[] args)
	    {
	            boolean contain= false;
	            int valeurATrouver=5;
	            int ints[] ={1,4,5};
	     
	        for(int i=0;i<ints.length;i++)
	        {
	            if(ints[i]==valeurATrouver)
	            {
	                contain=true;
	            }
	        }
	        if(contain){System.out.println("La valeur "+valeurATrouver+" est comprise dans le tableau");}
	        else{System.out.println("La valeur "+valeurATrouver+" n'est pas comprise dans le tableau");}
	    }
	}
Posted by: Guest on September-20-2021
0

java to python converter

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);
        }
    }
}
Posted by: Guest on May-25-2021
0

java to python converter

public static List<Integer> contacts(final List<String> queries) {
        // Write your code here
        final List<Integer> results = new ArrayList<>();
        final List<String> adds = new ArrayList<>();

        queries.forEach(contact -> {
            if (contact.startsWith("find")) {
                String find = contact.replaceAll("find ", "");
                results.add((int) adds.stream().filter(add -> add.startsWith(find)).count());
            } else {
                adds.add(contact.replaceAll("add ", ""));
            }
        });

        return results;
    }
Posted by: Guest on June-27-2021
0

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]))
Posted by: Guest on May-28-2021
0

convert java to python online

public class Bank {

    private static Map<String, String> bankList = new HashMap<String, String>();

    public static void generateList() {
        Connection conn = null;
        Statement stmt = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection(DATABASE_URL, DATABASE_USER, DATABASE_PASSWORD);

            //String sql = "SELECT institution_id_code, bank_full_name FROM IRIS.tblnpsbinstitutionid";
            String sql = "SELECT institution_id_code, bank_full_name FROM BBL_IRISINAPP.tblnpsbinstitutionid";
            
            stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);

            while(rs.next()) {
                String instCode = rs.getString("institution_id_code");
                String name = rs.getString("bank_full_name");

                bankList.put(instCode, name);
            }

            rs.close();
            stmt.close();
            conn.close();

        } catch (Exception e) {
        	e.printStackTrace();
            System.out.println("Error in generating bank list");
            System.exit(1);
        } finally {
            try {
                if (stmt != null)
                    stmt.close();
            } catch (SQLException se2) {
            }
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
    }


    public static String get(String institutionCode) {
        return bankList.get(institutionCode);
    }
}
Posted by: Guest on October-10-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language