简体   繁体   中英

Using Eclipse for java getting cannot be resolved for scanner. Anyone know what I have done wrong?

Secondary question is im notcing that not all of my code is changing colors to signify itself. IN this screenshot https://puu.sh/xCe5B/b2ef5f8948.png

You will see race14 is not turning cyan like the rest. Also the Math.min function is not working changing colors.

My 3rd question is, Is the way I am doing Math.min right?

//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: " +

}

Your problem might just be eclipse bugging. Whatever...

Your code looks good so far. You're missing some brackets in the end. I completed your code and it works for me:

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);
    }
}

Also have a look here for Math.min: https://www.tutorialspoint.com/java/lang/math_min_int.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM