mardi 13 mars 2018

How do I make my program output the shortest country entered by the user.Here is what I have right now

Here is my code right now. I'm stuck trying to find how I can output to the user the shortest country entered.

public class Countries {
    public static void main(String[] args) {


    Scanner scan = new Scanner (System.in);

    String  country;
    int count = 0;
    int smallest = 0;
    System.out.println(" Enter a country name or press stop to quit");
    country = scan.nextLine();
    while (! country.equals("stop")){
        System.out.println(" Enter a country name or press stop to quit");
        country = scan.nextLine();
        count++;
            smallest = country.length();
    if ( country.length() < smallest){
     String shortest = new String (country);
    }
    }
    System.out.println(" You entered " + count + " countries and" + shortest + " was the smallest enterd");


    }

}

Aucun commentaire:

Enregistrer un commentaire