convert java code to c 2b 2b online

Solutions on MaxInterview for convert java code to c 2b 2b online by the best coders in the world

showing results for - "convert java code to c 2b 2b online"
Teddy
24 May 2019
1class Pair implements Comparable<Pair> {
2    public:
3      int wsf;
4      string psf;
5
6      Pair(int wsf, string psf){
7         this->wsf = wsf;
8         this->psf = psf;
9      }
10
11  int compareTo(Pair o){
12         return this->wsf - o->wsf;
13      }
14  }
15
Ivan
28 Oct 2020
1public class Jeep extends Vehicle{
2
3    public Jeep() {
4    }
5
6    public Jeep(String vehicleType, int enginePower, int technology, float price, float tax, int wheelCategory, String registrationNumber) {
7        super(vehicleType, enginePower, technology, price, tax, wheelCategory, registrationNumber);
8    }
9
10    @Override
11    public float getPrice() {
12        return (enginePower * 3500 * wheelCategory) + 1000 + (technology * 1000);
13    }
14
15    @Override
16    public float getTax() {
17        return (this.getPrice() * 0.2f) + 200;
18    }
19}
Camilla
18 Jan 2017
1import edu.princeton.cs.algs4.CollisionSystem;
2import edu.princeton.cs.algs4.Particle;
3import edu.princeton.cs.algs4.StdDraw;
4public class TestAlgs4 {
5    public static void main(String[] args) {
6        int n = 20;  // number of particles (default 20)
7        if (args.length == 1) {
8            n = Integer.parseInt(args[0]);}
9        // enable double buffering to support animations
10        StdDraw.enableDoubleBuffering();
11        // create the n particles
12        Particle[] particles = new Particle[n];
13        for (int i = 0; i < n; i++) {
14            particles[i] = new Particle();
15        }
16        // simulate the system
17        CollisionSystem system = new CollisionSystem(particles);
18        system.simulate(Double.POSITIVE_INFINITY);
19    }
20}
Angelo
10 Jul 2019
1import java.util.Scanner;
2public class Exersice_05 {
3
4    public static void main(String[] Strings) {
5
6        double gratuityRate,
7                gratuityTotal,
8                total,
9                subtotal;
10
11        Scanner input = new Scanner(System.in);
12
13        System.out.print("Please enter the subtotal and gratuity rate: ");
14        subtotal = input.nextDouble();
15        gratuityRate = input.nextDouble();
16
17        gratuityTotal = subtotal * gratuityRate * .01;
18        total = subtotal + gratuityTotal;
19
20        System.out.print("The gratuity is $" + gratuityTotal + " and total is $" + total);
21
22    }
23}
Lianne
05 Jan 2019
1// Client side implementation of UDP client-server model
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <string.h>
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <arpa/inet.h>
9#include <netinet/in.h>
10
11#define PORT	 8080
12#define MAXLINE 1024
13
14// Driver code
15int main() {
16	int sockfd;
17	char buffer[MAXLINE];
18	char *hello = "Hello from client";
19	struct sockaddr_in	 servaddr;
20
21	// Creating socket file descriptor
22	
23	close(sockfd);
24	return 0;
25}
26
Brooklynn
10 Sep 2018
1public int rotatedWords(String input1, int input2) {
2    int c= 0;
3    String arr[] = input1.split(" ");
4    if (input1 != null && !input1.isEmpty()) {
5        for (int i = 0; i < arr.length; i++) {
6            String s1 = arr[i] + arr[i];
7            int start = arr[i].length() - input2;
8
9            System.out.println("arr[i] : " + arr[i]);
10            String s2 = s1.substring(start, start + arr[i].length());
11            System.out.println("s2 : " + s2);
12            if (s2.equalsIgnoreCase(arr[i])) {
13                count++;
14            }
15        }
16    }
17    return count;
18}
Paul
29 Jan 2019
1public static int findMaximum(List<Integer> arr, int m) {
2
3            long l = 1 , r = (long)(1e9);
4
5           
6
7            while(l<=r){
8
9                long mid = (l+r)/2;
10
11                
12
13                if(!bool(arr , mid , m)) r = mid-1;
14
15                else l = mid+1;
16
17            }
18
19            
20
21            return (int)r; 
22
23            
24
25    }
26
27    static boolean bool(List<Integer> arr , long dif , int m){
28
29        int prv = 0;
30
31        int c = 1;
32
33        for(int i = 1 ; i<arr.size() ; i++){
34
35            if(arr.get(i) - arr.get(prv) >= dif){
36
37                prv = i;
38
39                c++;
40
41            }
42
43        }
44
45        if(c>=m) return true;
46
47        return false;
48
49    }
50    
51
Amie
17 Nov 2020
1import java.util.*;
2
3class Pair{
4	int totalNodes, totalSum;
5	Pair(int total, int sum){
6		this.totalNodes = total;
7		this.totalSum = sum;
8	}
9}
10
11class MaxTenureFinder
12{
13	public static Pair findHighestTenure(HashMap<Integer, ArrayList<Integer>> hmap, int V){
14		if(hmap.get(V).size() == 0){
15			return new Pair(1, V);
16		}
17		else{
18			int totalNodesCount = 1;
19			int totalSum = V;
20			for(int i=0;i<hmap.get(V).size();i++){
21				Pair temp = findHighestTenure(hmap, hmap.get(V).get(i));
22				totalNodesCount += temp.totalNodes;
23				totalSum += temp.totalSum;
24			}
25			
26			if(totalSum * maxSum.totalNodes >= maxSum.totalSum * totalNodesCount){ // logic to avoid precision error
27				maxSum.totalNodes = totalNodesCount;
28				maxSum.totalSum = totalSum;
29				maxTenureNode = V;
30			}
31			
32			return new Pair(totalNodesCount, totalSum);
33		}
34	}
35	
36	public static int maxTenureNode;
37	public static Pair maxSum;
38	
39	public static void main (String[] args) throws java.lang.Exception
40	{
41		Scanner sc = new Scanner(System.in);
42		int n = sc.nextInt();
43		
44		HashMap<Integer, ArrayList<Integer>> hmap = new HashMap<> ();
45		
46		for(int i=0;i<n;i++){
47			int parent = sc.nextInt();
48			int child = sc.nextInt();
49			if(hmap.containsKey(parent)){
50				hmap.get(parent).add(child);
51			}
52			else{
53				ArrayList<Integer> temp = new ArrayList<> ();
54				temp.add(child);
55				hmap.put(parent, temp);
56			}
57			if(!hmap.containsKey(child)){
58				hmap.put(child, new ArrayList<> ());
59			}
60		}
61		int parentNode = sc.nextInt();
62		maxSum = new Pair(0, 0);
63		maxTenureNode = -1;
64		findHighestTenure(hmap, parentNode);
65		System.out.println(maxTenureNode);
66	}
67}
Linus
13 Aug 2017
1class I{
2  int i;
3  public void printNum(){
4    System.out.println(i);
5  }
6}
7
8class J extends I{
9  int j;
10  public void printNum(){
11    System.out.println(j);
12  }
13}
14
15class Ans{
16  public static void main(String[] args){
17    J a = new J();
18    a.i = 5;
19    a.j = 7;
20    a.j = a.i;
21    a.printNum();
22  }
23}
Hugo
29 Jan 2016
1import edu.princeton.cs.algs4.CollisionSystem;
2import edu.princeton.cs.algs4.Particle;
3import edu.princeton.cs.algs4.StdDraw;
4public class TestAlgs4 {
5    public static void main(String[] args) {
6        int n = 20;  // number of particles (default 20)
7        if (args.length == 1) {
8            n = Integer.parseInt(args[0]);
9        }
10        // enable double buffering to support animations
11        StdDraw.enableDoubleBuffering();
12        // create the n particles
13        Particle[] particles = new Particle[n];
14        for (int i = 0; i < n; i++) {
15            particles[i] = new Particle();}
16        // simulate the system
17        CollisionSystem system = new CollisionSystem(particles);
18        system.simulate(Double.POSITIVE_INFINITY);
19    }
20}