I can't seem to figure out whats wrong with my logic for the is it a function or not area. I used the following given test with the correct output:

f(1) = 1
f(2) = 4
f(3) = 3
f(4) = 1
f(5) = 1

This function is a valid function.
This function is not a one-to-one function.
This function is not onto.
This function is not a bijection.

Unfortunately, this is what i get:

f(1): 1
f(2): 4
f(3): 3
f(4): 1
f(5): 1
Is NOT a function

I can't seem to pinpoint the problem. feel free to point out any other problems if there's any after the function validation, thanks.

import java.util.Scanner;

public class Functions_2
{

   public static void main(String[] argv)
   { 

	//function f = {1, 2, 3, 4, 5}
	int[ ][ ] Function = new int [10][2];
	int[ ] Onto = new int [5];
	int Ordered_Pairs_Limit = 0;
	int Condition = 0;
		
	boolean Result = true;
	boolean One_to_One = true;
	boolean On_to = true;
	boolean Bi_jective = true;
		
	Scanner in = new Scanner (System.in);
	System.out.print("Enter number of ordered pairs: ");
		Ordered_Pairs_Limit = in.nextInt();
		
	for (int f = 0; f < Ordered_Pairs_Limit; f++)
	{
	    System.out.print("Enter an ordered pair: "); //Prompts for ordered pairs
		Function[f][0] = in.nextInt();
		Function[f][1] = in.nextInt();
	}
		
	for (int f = 0; f < Ordered_Pairs_Limit; f++) 
          //Tests if the ordered pair 1 is a function
	{	
	   Condition = Function[f][0];
	   for (int n = f + 1; n < Ordered_Pairs_Limit; n++)
	   {
	     if (Condition == Function[n][0] || Function[n][0] < 1 || Function [n][0] > 5)
		{
		   Result = false;
		}
						
	   }			
		Condition = Function[f][1];
		if (Condition < 1 || Condition > 5)
		{
		   Result = false;
		}
			
	}
		
//Calulating for valid functions, One to One, Onto, and Bijection
//-------------------------------------------------------------------------
	
			
      for (int f = 0; f < Ordered_Pairs_Limit; f++) 
        //Tests if the ordered pair is One to One
      {
	   Condition = Function[f][1];
	   if (Condition == Function[f][1])
		{
		   Result = false;
		}
      }
	
	for (int f = 0; f < Ordered_Pairs_Limit; f++) 
        //Tests if the ordered pair is Onto
	{
	   if (Ordered_Pairs_Limit < 5)
		{
		   On_to = false;
		}
					
	   if (Function[f][1] < 5)
		{
		   On_to = false;
		}
					
	   if (Function[f][0] != Function[f][1])
		{
		   On_to = false;
		}
				
       }
		
	   if (One_to_One = true && On_to == true) 
           //Tests if the ordered pair is Bijective
	   {
	      Bi_jective = true;
	   }
		
	        else
		{
		   Bi_jective = false;
		}
		
		//Prints out results
		
for (int f = 0; f < Ordered_Pairs_Limit; f++)
{
	   System.out.println("f(" + Function[f][0] + "): " + Function[f][1]);
	}
			
	if(Result == true)
	{
	   System.out.println( );
	   System.out.println("Is a function");
				
		if (One_to_One == true)
		{
		   System.out.println("This is a one to one function");
		}
					
		else
		{
		   System.out.println("This is NOT a one to one function");
		}
						
	if (On_to == true)
	{
	   System.out.println("This is an onto function");
	}
						
	else
	{
	   System.out.println("This is NOT an onto function");
	}
							
	if (Bi_jective == true)
	{
	   System.out.println("This is a bijective function");
	}
							
	else
	{
	   System.out.println("This is NOT a bijective function");	
	}
							
							
}
		
else
{
   System.out.print("Is NOT a function");
}
		
	}
	


}

What are those 1 and 5? Function[n][0] < 1 || Function [n][0] > 5 They are suppose to by dynamic. The user is the one that enters those values. 1 nad 5 have no meaning. Why any function must be between those ranges? Couldn't it be this function:
f(50)=100
f(100)=1000

This article has been dead for over six months. Start a new discussion instead.