Hey guys, wasn't sure where to post this but i posted it in both categories. Converting the for loop is probably the most confusing for me especially the arrays. Hope you guys can help me out, thanks.

#include <iostream>
using namespace std;

int main()	
{
	int Function[10][2] = {0};
	int Onto_Array[5] = {0};
	int Elements = 0;

	bool Valid = true, One_to_One = true, On_To = true;
	bool Bijective = true;
	
	cout << "Enter number of ordered pairs" << endl;
	cin >> Elements;
	
	for (int i = 0; i < Elements; i++)
	{
			cout<< "Enter ordered pair" << endl;
			cin >> Function[i][0];
			cin >> Function[i][1];
	}

}
Member Avatar for coil

Actually, C++ syntax is very similar to Java. The for-loop syntax is the same, and the array syntax is very similar.

To declare a 2D int array of dimensions 10 and 2: int[][]array=new int[10][2]; Same with single dimension arrays - declare the array size on the right side of the equal sign.

A few tips:
1. Replace cout with System.out.println("text here")
2. There is no direct equivalent to cin, but look into the Scanner class. Calling [Scanner object].next() will take in input.
3. The bool keyword in Java is boolean.
4. Get rid of the #include and using namespace. The Java equivalent is import java.[package name]
5. You need a main class and a main method (similar to the int main()). A basic class looks like this:

public class Test {
	public static void main(String[]args) {
		/*This is the main method. It returns void and takes in an array of 
		 *arguments
		 */
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.