我不知道为什么它总是说标题错误 我的问题是“为什么我的StringTokenizer不起作用?”尽管它可以在“用户输入X时”的第一个输入中使用, 但在“ a [i] = Integer.parseInt(st.nextToken());”处它不起作用。 程序功能是声明一个没有朋友的组,这些朋友互相给钱,最后我们从0看到他们每个人如何受益“ + sign result“ MONEY””,或者如果他输了,即:他给的钱超过了他收到的钱,所以这是“ -sign结果“钱””
package test2;
/*
ID: toti5821
TASK: gift1
LANG: JAVA
*/
import java.util.*;
import java.io.*;
import java.util.StringTokenizer;
public class test2 {
public static void main(String[]args) throws IOException{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new FileWriter("gift1.out"));
Scanner scan = new Scanner(System.in);
StringTokenizer st = new StringTokenizer(f.readLine());
int x = Integer.parseInt(st.nextToken());
HashMap<String,Integer> nameandmoney = new HashMap<String, Integer>();
for(int i=0;i < x;i++){
String name = f.readLine();
nameandmoney.put(name, 0);
}
for(int i=0;i<=x;i++) {
String thisname = f.readLine();
int size = 2;
int[] a= new int[size];
for (int j = 0; j < size; j++) {
a[i] = Integer.parseInt(st.nextToken());
}
System.out.println(a[1]);
nameandmoney.put(thisname,nameandmoney.get(thisname) - a[0]);
int leftover =a[0]%a[1];
nameandmoney.put(thisname,nameandmoney.get(thisname) + leftover);
int gift1 = a[0]/a[1];
if(a[1]==0) {
gift1=0;
}
for(int k=0;k<a[1];k++) {
String reciever = f.readLine();
nameandmoney.put(reciever,nameandmoney.get(reciever) - gift1);
}
} for(String names: nameandmoney.keySet()) {
out.println(names+" "+nameandmoney.get(names));
} } }