我需要一些帮助,用java开始这个离散数学。I';我完全不知所措
您的任务是生成从X={a,b,c}到集合Y的所有可能函数 整数1,…,对于某些整数n≥1.n的值由用户提供。定义 函数,您需要指定它为X的每个元素输出的内容。例如,如果Y={1,2}, 那么f(a)=1,f(b)=2,f(c)=2定义了从X到Y的函数f n的值由用户提供。要定义函数,您需要指定它为X的每个元素输出的内容。例如,如果Y={1,2},则f(a)=1,f(b)=2,f(c)=2定义从X到Y的函数f 编写一个程序,提示用户输入Y的大小,然后生成、枚举并以整洁的格式打印出从X到Y的所有可能函数。您的程序应该对生成的函数f1、f2、f3、f4等进行编号。对于每个生成的函数,无论是一对一、ON还是双射,都要输出。计算生成的函数总数,其中有多少是一对一的,有多少是上的,有多少是双射的我需要一些帮助,用java开始这个离散数学。I';我完全不知所措,java,one-to-one,discrete-mathematics,Java,One To One,Discrete Mathematics,您的任务是生成从X={a,b,c}到集合Y的所有可能函数 整数1,…,对于某些整数n≥1.n的值由用户提供。定义 函数,您需要指定它为X的每个元素输出的内容。例如,如果Y={1,2}, 那么f(a)=1,f(b)=2,f(c)=2定义了从X到Y的函数f n的值由用户提供。要定义函数,您需要指定它为X的每个元素输出的内容。例如,如果Y={1,2},则f(a)=1,f(b)=2,f(c)=2定义从X到Y的函数f 编写一个程序,提示用户输入Y的大小,然后生成、枚举并以整洁的格式打印出从X到Y的所有可能
public class Main {
public static void main(String[] args) {
Set<Integer> yGroup = new HashSet<>();
int n;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter value of n:");
n = Integer.parseInt(scanner.nextLine());
scanner.close();
for (int i = 1; i <= n; i++) {
yGroup.add(i);
}
int nf = 1;
int oneToneCounter = 0;
int ontoCounter = 0;
int bijectCounter = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
System.out.print("f" + nf + "(a)=" + i + " ");
System.out.print("f" + nf + "(b)=" + j + " ");
System.out.print("f" + nf + "(c)=" + k + " ");
System.out.println();
boolean injective = false;
if ((i == j) || (i == k) || (j == k)) {
System.out.print("f" + nf + " is not a one to one. ");
} else {
System.out.print("f" + nf + " is a one to one. ");
oneToneCounter++;
injective = true;
}
yGroup.remove((Integer) i);
yGroup.remove((Integer) j);
yGroup.remove((Integer) k);
boolean onto = false;
if (yGroup.isEmpty()) {
System.out.print("Is an onto. ");
onto = true;
ontoCounter++;
} else {
System.out.print("Is not an onto. ");
}
yGroup.add((Integer) i);
yGroup.add((Integer) j);
yGroup.add((Integer) k);
if (injective && onto) {
System.out.print("Is bijective. ");
bijectCounter++;
} else {
System.out.print("Is not bijective. ");
}
System.out.println();
System.out.println();
nf++;
}
}
}
System.out.println();
System.out.println("There are " + nf + " functions total");
System.out.println(oneToneCounter + " of them are one-to-one");
System.out.println(ontoCounter + " of them are onto");
System.out.println(bijectCounter + " of them are bijections");
}
}
该程序将生成从X={a,b,c}到Y={1,…,n}的所有函数
请输入n:2的值
f1(a)=1 f1(b)=1 f1(c)=1
f1不是一对一,不是一对一,也不是双射
f2(a)=1 f2(b)=1 f2(c)=2
f2不是一对一、对上,也不是双射
f3(a)=1 f3(b)=2 f3(c)=1
f3不是一对一、对上,也不是双射
f4(a)=1 f4(b)=2 f4(c)=2
f4不是一对一、对上,也不是双射
f5(a)=2 f5(b)=1 f5(c)=1
f5不是一对一、对上,也不是双射
f6(a)=2 f6(b)=1 f6(c)=2
f6不是一对一、对上,也不是双射
f7(a)=2 f7(b)=2 f7(c)=1
f7不是一对一、对上,也不是双射
f8(a)=2 f8(b)=2 f8(c)=2
f8不是一对一,不是一对一,也不是双射
共有8个功能
其中0个是一对一的
其中6人已被逮捕
其中0个是双射。公共类Main{
public class Main {
public static void main(String[] args) {
Set<Integer> yGroup = new HashSet<>();
int n;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter value of n:");
n = Integer.parseInt(scanner.nextLine());
scanner.close();
for (int i = 1; i <= n; i++) {
yGroup.add(i);
}
int nf = 1;
int oneToneCounter = 0;
int ontoCounter = 0;
int bijectCounter = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
System.out.print("f" + nf + "(a)=" + i + " ");
System.out.print("f" + nf + "(b)=" + j + " ");
System.out.print("f" + nf + "(c)=" + k + " ");
System.out.println();
boolean injective = false;
if ((i == j) || (i == k) || (j == k)) {
System.out.print("f" + nf + " is not a one to one. ");
} else {
System.out.print("f" + nf + " is a one to one. ");
oneToneCounter++;
injective = true;
}
yGroup.remove((Integer) i);
yGroup.remove((Integer) j);
yGroup.remove((Integer) k);
boolean onto = false;
if (yGroup.isEmpty()) {
System.out.print("Is an onto. ");
onto = true;
ontoCounter++;
} else {
System.out.print("Is not an onto. ");
}
yGroup.add((Integer) i);
yGroup.add((Integer) j);
yGroup.add((Integer) k);
if (injective && onto) {
System.out.print("Is bijective. ");
bijectCounter++;
} else {
System.out.print("Is not bijective. ");
}
System.out.println();
System.out.println();
nf++;
}
}
}
System.out.println();
System.out.println("There are " + nf + " functions total");
System.out.println(oneToneCounter + " of them are one-to-one");
System.out.println(ontoCounter + " of them are onto");
System.out.println(bijectCounter + " of them are bijections");
}
}
公共静态void main(字符串[]args){
Set yGroup=new HashSet();
int n;
扫描仪=新的扫描仪(System.in);
System.out.println(“输入n的值:”);
n=Integer.parseInt(scanner.nextLine());
scanner.close();
对于(int i=1;i)你尝试过什么,对吗?这实际上是一个刚刚粘贴的家庭作业?你尝试过什么?