Answers for "java to python"

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

package myproject;

import java.util.Scanner;

public class SEGP {

	public static void main(String[] args) {
		int n,j=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int a[]=new int[n+1]; 
		int b[] = new int[n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();

		for(int i=0;i<n;i++)
		{
			if(a[i]<a[i+1])
			{
				b[j]= a[i+1];
				j++;
			}
		}
	    	b[j]=a[n-1];
		for(int i=0;i<j+1;i++)
			System.out.print(b[i]+" ");
        sc.close();
	}

}
Posted by: Guest on July-18-2021
0

java to python

hrs = input("Enter Hours:")
h = float(hrs)
rph=float(input("Enter rate per hours:"))
if hrs>40:
    print (40*rph +(h-40)*rph*1.5)
else:
    print(h*rph)
Posted by: Guest on July-28-2021
0

java to python

import javax.swing.*;

public class Exe4{
	//metodo para calculo de Potencia
public static int exp(int n1,int n2)   
{
	int i=0, total=0;
	
	while(i<=n2)
	{
			total = n1*n2;	
			i++;
	}
	return total; 
    
}
  
       
	//metodo principal
	public static void main(String args[]){
		//Declaração de Variáveis
		int num1, num2;
		
		//Entrada de Dados do Usuário
		num1 = Integer.parseInt(JOptionPane.showInputDialog("Digite um número"));  
		num2 = Integer.parseInt(JOptionPane.showInputDialog("Digite outro número"));  
		
		//Exibição dos dados
		
		JOptionPane.showMessageDialog(null, exp(num1,num2));
		
	}
	
}
Posted by: Guest on July-13-2021
0

java to python

package myproject;

import java.util.Scanner;

public class SEGP {

	public static void main(String[] args) {
		int n,j=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int a[]=new int[n+1]; 
		int b[] = new int[n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();

		for(int i=0;i<n;i++)
		{
			if(a[i]<a[i+1])
			{
				b[j]= a[i+1];
				j++;
			}
		}
	    	b[j]=a[n-1];
		for(int i=0;i<j+1;i++)
			System.out.print(b[i]+" ");
        sc.close();
	}

}
Posted by: Guest on July-18-2021
0

java to python

package com.company;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
   // write your code here
        int key1 =0;
        int key2 =0;
        int key33 = 0;
        int KEY;
        int[] key3 = new int[4];

        Scanner girdi = new Scanner(System.in);
        System.out.println("Please write 1000 <= input1 <= 9999 ");
        int input1 = girdi.nextInt;
        System.out.println("Please write 1000 <= input2 <= 9999 ");
        int input2 = girdi.nextInt;
        System.out.println("Please write 1000 <= input3 <= 9999 ");
        int input3 = girdi.nextInt;

        while(input1 >= 1000) {
            input1 = input1 - 1000;
            input1 = input1;
        }
        while(input1 >= 100) {
            input1 = input1 - 100;
            key1 = key1 + 1;
        }
        while(input2 >= 100) {
            input2 = input2 - 100;
            input2 = input2;
        }
        while(input2 >= 10) {
            input2 = input2 - 10;
            key2 = key2 + 1;
        }

        key3[0]=input3/1000;  
        input3=input3-(1000*key3[0]);

        key3[1]=input3/100;   
        input3=input3-(100*key3[1]);

        key3[2]=input3/10;    
        input3=input3-(10*key3[2]);

        key3[3]=input3;     

        key33 = Arrays.stream(key3).max.getAsInt;

        KEY = (key1 * key2) - key33;

        System.out.println("Hundreds digit of input1 = " + key1);
        System.out.println("Tens digit of input2 = " + key2);
        System.out.println("Largest digit of input3 = " + key33);
        System.out.println("KEY = " + KEY);
        
    }
}
Posted by: Guest on September-15-2021
0

java to python

import javax.swing.*;

public class Exe4{
	//metodo para calculo de Potencia
public static int exp(int n1,int n2)   
{
	int i=0, total=0;
	
	while(i<=n2)
	{
			total = n1*n2;	
			i++;
	}
	return total; 
    
}
  
       
	//metodo principal
	public static void main(String args[]){
		//Declaração de Variáveis
		int num1, num2;
		
		//Entrada de Dados do Usuário
		num1 = Integer.parseInt(JOptionPane.showInputDialog("Digite um número"));  
		num2 = Integer.parseInt(JOptionPane.showInputDialog("Digite outro número"));  
		
		//Exibição dos dados
		
		JOptionPane.showMessageDialog(null, exp(num1,num2));
		
	}
	
}
Posted by: Guest on July-13-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language