Answers for "convert java code to c++ online"

0

convert java code to c++ online

import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the number of widgets bought");
        int n = input.nextInt();
        System.out.println("the sub total of "+n+" widgets is $" + (2*n) +"\n");
        //assuming sales tax is 14%
        float st=(float)n*2;
        st=st*0.14f;
        st=st+(float)(n*2);
        float st1 = st;
        System.out.println("the sub total of "+n+" widgets after adding sales tax is $" + st +"\n");
        System.out.println("which delivery you want\n1=> ground delivery\n2=>express delivery");
        int c = input.nextInt();
        float sf;
        if(c==1)
        {
            st=st+4.95f;
            sf=4.95f;
            System.out.println("the total of "+n+" widgets after adding delivery charges $" + st +"\n");
        }
        else {
            System.out.println("which express delivery you want\n1=> 2 days delivery\n2=>overnight delivery");
            int d = input.nextInt();
            if (d == 1) {
                st=(st + 9.95f);
                sf=9.95f;
                System.out.println("the total of " + n + " widgets after adding delivery charges $" + st + "\n");
            } else {
                st=(st + 18.95f);
                sf=18.95f;
                System.out.println("the total of " + n + " widgets after adding delivery charges $" + st + "\n");
            }
        }
        System.out.println("number of widgets\t"+n);
        System.out.println("sub total\t"+((float)n*2.0f));
        System.out.println("sales tax\t"+st1);
        System.out.println("subtotal with tax\t"+(((float)n*2.0f))+st1);
        System.out.println("shipping fee\t"+sf);
        System.out.println("total  cost\t"+st);
        System.out.println("number of widgets\t"+n);



       // System.out.println("Press enter to exit");

    }
}
Posted by: Guest on October-15-2021
0

convert java code to c++ online

" + coded);
		// decode it back
		System.out.println(" Decoded: " + adfgvx.decode(coded));
		//---------------------------------------------
		// end of automatic tests
		//---------------------------------------------
		
		// now proceed with user input
		Scanner scan = new Scanner(System.in);
		System.out.print("\n    Enter a Key: ");
		String key = scan.nextLine();
		Adfgvx user = new Adfgvx(key);
		System.out.print("Enter a message: ");
		String msg = scan.nextLine();
		// dump the grid
		user.dumpGrid();
		System.out.println("  Key is: " + user.key);
		System.out.println("Original: " + msg);
		String cypher = user.encode(msg);
		System.out.println("   Coded: " + cypher);
		System.out.println(" Decoded: " + user.decode(cypher));
	}

	/**
	 * An internal class to hold the data (the character of each column)
	 * it implements comparable so the column could be sorted by alpahbetical order
	 */
	private class Column implements Comparable<Column> {

		// the letter A D F G V X at the head of the column
		private char header;
		// all the letters in the column
		private char[] letters;
		// use when we cumulate the digits in the letters array
		private int index;

		/**
		 * Constructor that receives the letter as header
		 */
		Column(char header) {
			this.header = header;
		}
		/**
		 * To set the number of elements in the column
		 */
		void setSize(int size) {
			// build array to receive all elements
			letters = new char[size];
			// reset that we are at element 0
			index = 0;
		}
		/** 
		 * To return, while decoding, the number of characters to insert in the Column
		 */
		int getSize() {
			return letters.length;
		}
		/**
		 * To add a letter to the column
		 */
		void add(char c) {
			letters[index++] = c;
		}
		/** 
		 * To get a single letter
		 */
		char getChar(int n) {
			return letters[n];
		}
		/**
		 * To return as a String the letters in the column
		 */
		public String toString() {
			return new String(letters);
		}
		
		/**
		 * To sort the columns by header
		 */
		public int compareTo(Column other) {
			return header - other.header;
		}
	}

}
Posted by: Guest on July-22-2021
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;
    }
Posted by: Guest on August-18-2021
0

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;
      }
  }
Posted by: Guest on August-21-2021
0

convert java code to c++ online

import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner in=new Scanner(System.in);
      int n=in.nextInt();
      for(int i=1;i<=n;i++){
          for(int j=1;j<=i;j++){
              System.out.print(j*j+" ");
          }
          System.out.println();
      }
      
    }
}
Posted by: Guest on July-06-2021
0

convert java code to c++ online

import edu.princeton.cs.algs4.CollisionSystem;
import edu.princeton.cs.algs4.Particle;
import edu.princeton.cs.algs4.StdDraw;
public class TestAlgs4 {
    public static void main(String[] args) {
        int n = 20;  // number of particles (default 20)
        if (args.length == 1) {
            n = Integer.parseInt(args[0]);}
        // enable double buffering to support animations
        StdDraw.enableDoubleBuffering();
        // create the n particles
        Particle[] particles = new Particle[n];
        for (int i = 0; i < n; i++) {
            particles[i] = new Particle();
        }
        // simulate the system
        CollisionSystem system = new CollisionSystem(particles);
        system.simulate(Double.POSITIVE_INFINITY);
    }
}
Posted by: Guest on September-26-2021
0

convert java code to c++ online

import java.util.Scanner;
public class Exersice_05 {

    public static void main(String[] Strings) {

        double gratuityRate,
                gratuityTotal,
                total,
                subtotal;

        Scanner input = new Scanner(System.in);

        System.out.print("Please enter the subtotal and gratuity rate: ");
        subtotal = input.nextDouble();
        gratuityRate = input.nextDouble();

        gratuityTotal = subtotal * gratuityRate * .01;
        total = subtotal + gratuityTotal;

        System.out.print("The gratuity is $" + gratuityTotal + " and total is $" + total);

    }
}
Posted by: Guest on September-17-2021
0

convert java code to c++ online

System.out.println("Max Value:\t" + B[n][M]);

	System.out.println("Selected Packs: ");
Posted by: Guest on July-29-2021
0

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)) + "%");
    }
}
Posted by: Guest on October-20-2021
0

convert java code to c++ online

public int rotatedWords(String input1, int input2) {
    int c= 0;
    String arr[] = input1.split(" ");
    if (input1 != null && !input1.isEmpty()) {
        for (int i = 0; i < arr.length; i++) {
            String s1 = arr[i] + arr[i];
            int start = arr[i].length() - input2;

            System.out.println("arr[i] : " + arr[i]);
            String s2 = s1.substring(start, start + arr[i].length());
            System.out.println("s2 : " + s2);
            if (s2.equalsIgnoreCase(arr[i])) {
                count++;
            }
        }
    }
    return count;
}
Posted by: Guest on August-21-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language