![](/img/trans.png)
[英]java.io.FileNotFoundException (File not found) using Scanner. What's wrong in my code?
[英]Using Eclipse for java getting cannot be resolved for scanner. Anyone know what I have done wrong?
第二個問題是,並不是我的所有代碼都在改變顏色來表示自己。 在此屏幕截圖中https://puu.sh/xCe5B/b2ef5f8948.png
您會看到race14沒有像其他地方一樣變成青綠色。 此外,Math.min函數無法更改顏色。
我的第三個問題是,我做Math.min的方式正確嗎?
//input scanner
import java.util.Scanner;
public class Edmonds_Jonny_hw4p1.java {
public static void main(String[] args) {
// TODO Auto-generated method stub
//scanner input
Scanner input = new Scanner(System.in);
//prompt user to enter in race details
System.out.print("Enter the time for each runner for race 1, once"
+ "line");
int race11 = input.nextInt();
int race12 = input.nextInt();
int race13 = input.nextInt();
int race14 = input.nextInt();
int fastest1 = Math.min(race11, race12, Math.min(race13, race14));
//output fastest vs slowest for race 1
System.out.print("Race1: Fastest: " +
}
您的問題可能只是日食漏洞。 隨你...
到目前為止,您的代碼看起來不錯。 最后,您缺少一些括號。 我完成了您的代碼,它對我有用:
import java.util.Scanner;
public class Racers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("..."); //edit
int race11 = input.nextInt();
int race12 = input.nextInt();
int race13 = input.nextInt();
int race14 = input.nextInt();
int fastest1 = Math.min(Math.min(race11, race12), Math.min(race13, race14));
System.out.println("fastest time: " + fastest1);
}
}
也可以在此處查看Math.min: https ://www.tutorialspoint.com/java/lang/math_min_int.htm
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.