SHARE
TWEET

Java 11 iterar hashmap

a guest Jul 4th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Error en la línea 24
  2. import java.util.Arrays;
  3. import java.util.HashMap;
  4. import java.util.Scanner;
  5.  
  6. public class Question4Day2 {
  7.     public static void main(String[] args) {
  8.         HashMap studentsGrades = new HashMap<String, Double>();
  9.         Scanner inputScanner = new Scanner(System.in);
  10.         Double classAverage = 0.0;
  11.         //Double studentNumber = 0.0;
  12.         while (true) {
  13.             String name;
  14.             Double grade;
  15.             System.out.println("Student name:");
  16.             name = inputScanner.next();
  17.             System.out.println(name + "'s Grade");
  18.             grade = Double.parseDouble(inputScanner.next());
  19.             if (grade == -1) {
  20.                 //classAverage = classAverage/studentNumber;
  21.                 break;
  22.             } else {
  23.                 //**!LÍNEAS QUE DAN ERROR¡**
  24.                 for (HashMap.Entry<Double, Integer> studentGrade :
  25.                         studentsGrades.entrySet()
  26.                 ) {
  27.                     System.out.println("prueba");
  28.                 }
  29.                 /*Incompatible types.
  30.                 Required:Object
  31.                 Found: Entry<java.lang.String,java.lang.Double>*/
  32.                 //classAverage += grade;
  33.                 //studentNumber++;
  34.                 studentsGrades.put(name, grade);
  35.             }
  36.         }
  37.         System.out.println(Arrays.asList(studentsGrades));
  38.         System.out.println("Average of the class: " + classAverage);
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top