更改编号而不是候选人姓名 导入uulib.GUI; 导入java.util.Scanner; 导入uulib.Num; /** *在这里写下votes1类的描述。 * *@author(你的名字) *@version(版本号或日期) */ 公共课votes1 { 公共静态void main(字符串[]args) { 扫描仪输入=新扫描仪(系统输入); 字符串[]名称=新字符串[6];//名称 int[]投票=新的int[6];//候选人投票 int total_voces=0;//总票数 double[]百分比=新的double[6];//候选百分比 intthreshold=GUI.getInt(“输入阈值”); 对于(int i=0;i

更改编号而不是候选人姓名 导入uulib.GUI; 导入java.util.Scanner; 导入uulib.Num; /** *在这里写下votes1类的描述。 * *@author(你的名字) *@version(版本号或日期) */ 公共课votes1 { 公共静态void main(字符串[]args) { 扫描仪输入=新扫描仪(系统输入); 字符串[]名称=新字符串[6];//名称 int[]投票=新的int[6];//候选人投票 int total_voces=0;//总票数 double[]百分比=新的double[6];//候选百分比 intthreshold=GUI.getInt(“输入阈值”); 对于(int i=0;i,java,Java,将索引保留在winner(而不是投票)中。如 字符串[]名称: System.out.println("Winner: " + name[winner]); +----+----+----+----+ | 0 | 1 | 2 | 3 | <--Array index +----+----+----+----+ |Cdd1|Cdd2|Cdd3|Cdd4| <--Names of Candidates (String array) +----+----+----+----+

将索引保留在
winner
(而不是投票)中。如


字符串[]名称:

System.out.println("Winner: " + name[winner]);
+----+----+----+----+
| 0  | 1  | 2  | 3  |  <--Array index
+----+----+----+----+
|Cdd1|Cdd2|Cdd3|Cdd4|  <--Names of Candidates (String array)
+----+----+----+----+

打印低于阈值的候选人的姓名很容易。我认为您不需要正确存储候选人姓名?您只需调用一个非常简单的方法即可做到这一点:

System.out.println("Winner: " + "\t" + name[winner]);
publicstaticvoidmain(字符串[]args){
//低于临界值的候选人
打印低于阈值的值(阈值、名称、投票);
}
公共静态无效打印\u低于\u阈值(整数阈值,字符串[]名称,整数[]投票){

对于(In x=0;恐怕你需要显示更多的代码。你有没有一个类?我已经发布了整个分类添加了一个完整的解决方案,下面的解释,看看它。它应该帮助你现在和将来。我怎么能打印一个以上的名字为贝尔瓦席。我已经做了同样的方式,你已经表明我的赢家。。通过存储多个值。可能在
集合
中,如
ArrayList
List al=new ArrayList();al.add(1);al.add(2);System.out.println(al);
应该是
1,2
+----+----+----+----+
| 0  | 1  | 2  | 3  |  <--Array index
+----+----+----+----+
|Cdd1|Cdd2|Cdd3|Cdd4|  <--Names of Candidates (String array)
+----+----+----+----+
+----+----+----+----+
| 0  | 1  | 2  | 3  |  <--Array index
+----+----+----+----+
|120 |550 |330 |220 |  <--Votes of Candidates (int array)
+----+----+----+----+
System.out.println("Winner: " + "\t" + name[winner]);
public static void main(String[] args){
    //Candidates below threshold
    print_Below_Threshold(threshold, name, votes);
}

public static void print_Below_Threshold(int threshold, String[] name, int[] votes){
    for(int x=0; x<name.legnth; x++)
        if(votes[x] < threshold)
            System.out.print(name[x] + " ");    
}