显示消息未显示为GUI。目前我将输出消息设置为系统输出打印ln但我需要一个字符串输出来显示一条消息,指出列表是否相同。我怎样才能做出这个改变?我使用以下列表1 = 5 2 5 6 1 6和列表2 = 5 2 5 6 1 6这是更新的代码:
// Enter values for list1
String input = JOptionPane.showInputDialog ("Enter list1: ");
int size1 = Integer.parseInt(input);
int[] list1 = new int[size1];
for (int i = 0; i < list1.length; i++)
list1[i] = Integer.parseInt(input);
// Enter values for list2
String input2 = JOptionPane.showInputDialog ("Enter list2: ");
int size2 = Integer.parseInt(input2);
int[] list2 = new int[size2];
for (int i = 0; i < list2.length; i++)
list2[i] = Integer.parseInt(input2);
if (equals(list1, list2)) {
System.out.println("Two lists are strictly identical");
}
else {
System.out.println("Two lists are not strictly identical");
}
}
public static boolean equals(int[] list1, int[] list2) {
if (list1.length != list2.length)
return false;
for (int i = 0; i < list1.length; i++)
if (list1[i] != list2[i])
return false;
return true;
}
}