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
convert java code to c++ online
public static int findMaximum(List 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 arr , long dif , int m){
int prv = 0;
int c = 1;
for(int i = 1 ; i= 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 : ");
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> 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= 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> hmap = new HashMap<> ();
for(int i=0;i 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
convert java code to c++ online
// Client side implementation of UDP client-server model
#include
#include
#include
#include
#include
#include
#include
#include
#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 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 arr , long dif , int m){
int prv = 0;
int c = 1;
for(int i = 1 ; i= dif){
prv = i;
c++;
}
}
if(c>=m) return true;
return false;
}
convert java code to c++ online
class Pair implements Comparable {
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
|