online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/****************************************************************************** Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. *******************************************************************************/ import java.util.Arrays; public class Main { public static void main (String[]args) { // according to this video i will create the code // https://www.youtube.com/watch?v=yHVq0g6XWes int firstNumber = MyConsole.readInt ("give me the first number for the Egyption multiplication : "); // for example first number = 10 int secondNumber = MyConsole.readInt ("give me the second number for the Egyption multiplication : "); // for example second number = 30 System.out.println (firstNumber); System.out.println (secondNumber); // initializing the first number column of the ejyption multiplication int amountOfElements = 0; for (int i = 1; i < firstNumber; i *= 2) { // 1 2 4 8 are less then 10 amountOfElements++; } int[] firstNumberMulti = new int[amountOfElements]; // [0,0,0,0] int counter = 0; for (int i = 1; i < firstNumber; i *= 2) { firstNumberMulti[counter] = i; counter++; } // we will get [1,2,4,8] for the example where firstNumber = 10 System.out.println ("first number column: " + Arrays.toString (firstNumberMulti)); // now we will initilize the secondNumber array int[] secondNumberMulti = new int[amountOfElements]; // [0,0,0,0] for (int i = 0; i < secondNumberMulti.length; i++) // we will get for second Number = 30 [30,60,120,240] { secondNumberMulti[i] = secondNumber; secondNumber *= 2; } System.out.println ("the second Array is : " + Arrays.toString (secondNumberMulti)); // now we need to find a way to calculate which sum of numbers will be equals to // the firstNumber for (int i = 0; i < firstNumberMulti.length; i++) { int sumOfAll = 0; sumOfAll += firstNumberMulti[i]; } } }
/** * An easy interface to read numbers and strings from * standard input * @version 1.10 10 Mar 1997 * @author Cay Horstmann */ public class MyConsole { /** * print a prompt on the console but don't print a newline * @param prompt the prompt string to display */ public static void printPrompt(String prompt) { System.out.print(prompt + " "); System.out.flush(); } /** * read a string from the console. The string is * terminated by a newline * @return the input string (without the newline) */ public static String readString() { int ch; String r = ""; boolean done = false; while (!done) { try { ch = System.in.read(); if (ch < 0 || (char)ch == '\n') done = true; else if ((char)ch != '\r') // weird--it used to do \r\n translation r = r + (char) ch; } catch(java.io.IOException e) { done = true; } } return r; } /** * read a string from the console. The string is * terminated by a newline * @param prompt the prompt string to display * @return the input string (without the newline) */ public static String readString(String prompt) { printPrompt(prompt); return readString(); } /** * read a word from the console. The word is * any set of characters terminated by whitespace * @return the 'word' entered */ public static String readWord() { int ch; String r = ""; boolean done = false; while (!done) { try { ch = System.in.read(); if (ch < 0 || java.lang.Character.isWhitespace((char)ch)) done = true; else r = r + (char) ch; } catch(java.io.IOException e) { done = true; } } return r; } /** * read an integer from the console. The input is * terminated by a newline * @param prompt the prompt string to display * @return the input value as an int * @exception NumberFormatException if bad input */ public static int readInt(String prompt) { while(true) { printPrompt(prompt); try { return Integer.valueOf (readString().trim()).intValue(); } catch(NumberFormatException e) { System.out.println ("Not an integer. Please try again!"); } } } /** * read a floating point number from the console. * The input is terminated by a newline * @param prompt the prompt string to display * @return the input value as a double * @exception NumberFormatException if bad input */ public static double readDouble(String prompt) { while(true) { printPrompt(prompt); try { return Double.valueOf (readString().trim()).doubleValue(); } catch(NumberFormatException e) { System.out.println ("Not a floating point number. Please try again!"); } } } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue