[英]No line found for nextline/int
我尝试让用户在while循环中输入string和int中的一些值,但是,当我开始时我没有找到Line,我尽我所能来解决它,但没有任何对我有用。 我想知道如何让用户输入int和string的值。
public static void main(String[] args) throws IOException {
// TODO code application logic here
int saldo = 10000;
String anw = "j";
int cost;
//create file
File f = new File("C:\\Users\\ae65255\\Desktop\\file.txt");
try{
f.createNewFile();
System.out.println("23");
//frågan
while(anw.equals("j")){
Scanner fileIn = new Scanner(f);
System.out.println("Ange utgiftspost:"); //post
String post = fileIn.nextLine();
System.out.println("Ange kostnad:"); //kost
cost=fileIn.nextInt();
fileIn.nextLine();
saldo = +saldo -cost;
System.out.println("saldo:" +saldo);
System.out.println("Vill du mata in fler uppgifter? (j/n) :");
anw = fileIn.nextLine();
String fileContent = "---"+post+"---"+cost+"---"+saldo;
PrintWriter writer ;
writer = new PrintWriter(f);
writer.println(fileContent);
if (anw.equals("n")) {
fileIn.close();
writer.close();
//System.out.println("---"+post+"---"+cost+"---"+saldo);
}
} //frågan slut
}
catch(Exception e){
System.err.println(e.getMessage());
}//frågan
//System.out.println("---"+post+"---"+cost+"---"+saldo);
System.out.println("File path" +f.getPath());
}
}
@AKSW评论解决了我的两个答案。 Scanner in = new Scanner(System.in);
使用Scanner in = new Scanner(System.in);
让我从控制台获取用户输入。 另一个是阻止它覆盖文本,这是他对这篇文章的最新评论 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.