Horje
convert java code to c++ online Code Example
convert java code to c++ online
package no2;
import javax.swing.JOptionPane;
public class nama {
     public static void main(String[]args){
         String a = JOptionPane.showInputDialog("Masukkan nama :");
         String b = JOptionPane.showInputDialog("Masukkan jumlah angka :");
         String hasil ="";
         for(int i=0;i<Integer.parseInt(b);i++){
             hasil +="nama : "+a+"\n";
         }
      
         JOptionPane.showMessageDialog(null,hasil);
         
                
             
         }
        }    
convert java code to c++ online
public static int findMaximum(List<Integer> arr, int m) {

            long l = 1 , r = (long)(1e9);

           

            while(l<=r){

                long mid = (l+r)/2;

                

                if(!bool(arr , mid , m)) r = mid-1;

                else l = mid+1;

            }

            

            return (int)r; 

            

    }

    static boolean bool(List<Integer> arr , long dif , int m){

        int prv = 0;

        int c = 1;

        for(int i = 1 ; i<arr.size() ; i++){

            if(arr.get(i) - arr.get(prv) >= dif){

                prv = i;

                c++;

            }

        }

        if(c>=m) return true;

        return false;

    }
    
convert java code to c++ online
mport java.util.Scanner;

public class MaleFemalePercentage {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number of student in your class: ");
        int n = in.nextInt();
        int males = 0, females = 0;
        for (int i = 0; i < n; i++) {
            System.out.print("Enter student #" + (i + 1) + " gender <m/f>: ");
            if (in.next().equalsIgnoreCase("m")) {
                males++;
            } else {
                females++;
            }
        }
        System.out.println("Total percentage of male students in the class is: " + (males / (double) (males + females)) + "%");
        System.out.println("Total percentage of female students in the class is: " + (females / (double) (males + females)) + "%");
    }
}
convert java code to c++ online
import java.util.*;

class Pair{
	int totalNodes, totalSum;
	Pair(int total, int sum){
		this.totalNodes = total;
		this.totalSum = sum;
	}
}

class MaxTenureFinder
{
	public static Pair findHighestTenure(HashMap<Integer, ArrayList<Integer>> hmap, int V){
		if(hmap.get(V).size() == 0){
			return new Pair(1, V);
		}
		else{
			int totalNodesCount = 1;
			int totalSum = V;
			for(int i=0;i<hmap.get(V).size();i++){
				Pair temp = findHighestTenure(hmap, hmap.get(V).get(i));
				totalNodesCount += temp.totalNodes;
				totalSum += temp.totalSum;
			}
			
			if(totalSum * maxSum.totalNodes >= maxSum.totalSum * totalNodesCount){ // logic to avoid precision error
				maxSum.totalNodes = totalNodesCount;
				maxSum.totalSum = totalSum;
				maxTenureNode = V;
			}
			
			return new Pair(totalNodesCount, totalSum);
		}
	}
	
	public static int maxTenureNode;
	public static Pair maxSum;
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		HashMap<Integer, ArrayList<Integer>> hmap = new HashMap<> ();
		
		for(int i=0;i<n;i++){
			int parent = sc.nextInt();
			int child = sc.nextInt();
			if(hmap.containsKey(parent)){
				hmap.get(parent).add(child);
			}
			else{
				ArrayList<Integer> temp = new ArrayList<> ();
				temp.add(child);
				hmap.put(parent, temp);
			}
			if(!hmap.containsKey(child)){
				hmap.put(child, new ArrayList<> ());
			}
		}
		int parentNode = sc.nextInt();
		maxSum = new Pair(0, 0);
		maxTenureNode = -1;
		findHighestTenure(hmap, parentNode);
		System.out.println(maxTenureNode);
	}
}
convert java code to c++ online
public class Main {
    public static void main(String[] args) {
   // write your code here
        int j = 1;
        for(int k = 5; k >= 1; k--){
            for (int d = 1; d < k; d++ ){
                System.out.print(j+ " ");
                j += 1;
            }
            System.out.println();
        }
    }
}
convert java code to c++ online
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager">
    <output url="file://$MODULE_DIR$" />
    <output-test url="file://$MODULE_DIR$" />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
      <excludeFolder url="file://$MODULE_DIR$/.idea" />
      <excludeFolder url="file://$MODULE_DIR$/.lift" />
      <excludePattern pattern="*.iml" />
      <excludePattern pattern="*.class" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" exported="" name="algs4" level="project" />
  </component>
</module>
convert java code to c++ online
// Client side implementation of UDP client-server model
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#define PORT	 8080
#define MAXLINE 1024

// Driver code
int main() {
	int sockfd;
	char buffer[MAXLINE];
	char *hello = "Hello from client";
	struct sockaddr_in	 servaddr;

	// Creating socket file descriptor
	
	close(sockfd);
	return 0;
}
convert java code to c++ online
public static int findMaximum(List<Integer> arr, int m) {
            long l = 1 , r = (long)(1e9);
           
            while(l<=r){
                long mid = (l+r)/2;
                
                if(!bool(arr , mid , m)) r = mid-1;
                else l = mid+1;
            }
            
            return (int)r; 
            
    }
    static boolean bool(List<Integer> arr , long dif , int m){
        int prv = 0;
        int c = 1;
        for(int i = 1 ; i<arr.size() ; i++){
            if(arr.get(i) - arr.get(prv) >= dif){
                prv = i;
                c++;
            }
        }
        if(c>=m) return true;
        return false;
    }
convert java code to c++ online
class Pair implements Comparable<Pair> {
    public:
      int wsf;
      string psf;

      Pair(int wsf, string psf){
         this->wsf = wsf;
         this->psf = psf;
      }

  int compareTo(Pair o){
         return this->wsf - o->wsf;
      }
  }
convert java code to c++ online
package com.company;
import java.util.Random;
import java.util.Scanner;
public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);System.out.println("n=");
        int n = in.nextInt();int a[][] = new int[n][n];Random u = new Random();
        for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = u.nextInt(10);
                System.out.print(a[i][j]+"\t");}  System.out.println();}int C=0;
        System.out.println();for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) {
                if((j>=i)&&i+j<=n-1){System.out.print(a[i][j]+"\t");C+=a[i][j];
                }else if (j<=i && i+j>=n-1){  System.out.print(a[i][j]+"\t");C+=a[i][j];
                } else {
                    System.out.print("\t");     }
            }
            System.out.println();
        }
        System.out.println("C="+C);

    }
}0




Cpp

Related
copy constructor in c++ questions Code Example copy constructor in c++ questions Code Example
how to scan vector in c++ Code Example how to scan vector in c++ Code Example
play roblox vr on quest 2 Code Example play roblox vr on quest 2 Code Example
c++ rewrite file Code Example c++ rewrite file Code Example
python to c++ transpiler Code Example python to c++ transpiler Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9