/* This program contains some sample code to demonstrate basic C++ usage that is either identical to or similar to how it would be written in Java. Java C++ --------------------------------------------------------------------- int, double, char same boolean bool (also 0 is false, nonzero is true) x = y x = y or x {y} or x = {y} if/else statements same for loops same while loops same static methods functions define methods in any order use function prototypes System.out.print(...) cout << ...; System.out.println(...) cout << ... << endl; console Scanner (System.in) cin >> ...; import java.util.*; #include , using namespace std; */ #include #include using namespace std; // allows us to say things like cout instead of std::cout int main() { cout << "Hello world!" << endl << endl; for (int i = 1; i <= 10; i++) { cout << i << "-squared = " << i * i << endl; } cout << endl; cout << "give me a number to show factors of 2: "; int n; cin >> n; cout << n << " = "; while (n % 2 == 0) { cout << "2 * "; n /= 2; } cout << n << endl << endl; cout << "give me two ints to compute an exponent: "; int x, y; cin >> x >> y; cout << x << "^" << y << " = " << pow(x, y) << endl << endl; }