関数{1,2,3,4,5}が与えられています。彼が望む数のペアをユーザーから入力し、その関数が有効かどうかを確認する必要があります(x座標の値は1から5の間でなければならず、x座標は繰り返せません)。私はループの方法を知っていて、Xの値が1から5の間であるかどうかをチェックしますが、繰り返し要素の文字列をチェックするのに問題があります。私はxが1より小さく5より大きい条件式を書いていましたが、繰り返し要素をチェックする式を書く方法はわかりません。誰か助けてもらえますか?これは私がこれまで持っているものです。数学関数が有効かどうかを調べる
import java.util.Scanner;
public class Functions
{
public static void main (String args [])
{
Scanner in = new Scanner (System.in);
int []domain = new int [5];
int [] range = new int [5];
int orderedPairs = 0;
System.out.println ("Enter the number of ordered pairs please: ");
orderedPairs = in.nextInt();
while (orderedPairs < 0 || orderedPairs > 5)
{
System.out.println ("This input is invalid. Enter a number between 0 and 5 and try again:");
orderedPairs = in.nextInt();
}
for (int i = 0; i < orderedPairs; i++)
{
System.out.println ("Enter the x-coordinate please: ");
domain [i][0] = in.nextInt();
System.out.println ("Enter the y-coordinate please: ");
range [i][0] = in.nextInt();
}
for (int i = 0; i < orderedPairs; i++)
{
System.out.println ("f(" + domain [i][0] + "): " + range [i][0]);
}
for (int i = 0; i < orderedPairs;i++)
{
if (domain [i][0] > 5 || domain [i][0] < 1)
{
function = false;
}
for (int n = i + 1; n < orderedPairs; n++)
{
if (domain[i] == domain [n] && range [n] != range [i])
{
function = false;
}
}
}
}
}
編集: それは明らかに、取ったすべてです! :)
宿題の場合は、「宿題」タグを追加してください。 –