CommencerCommencer gratuitement

All the winners

You decide to save your favorites Nobel prize winners for Literature and Chemistry as well. Now, though, you are wondering how many favorites you have in the different fields - it's time to measure the length of the arrays!

Cet exercice fait partie du cours

Introduction to Java

Afficher le cours

Instructions

  • Print length of literatureLaureates using the .length property.
  • Print length of chemistryLaureates.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

class AllNobelLaureates {
    public static void main(String[] args) {
    
        String[] physicsLaureates = {"Curie", "Einstein", "Fermi"};        
        String[] literatureLaureates = {"Kipling", "Shaw", "Hemingway", "Seifert"};
        String[] chemistryLaureates = {"Curie", "Heyrovsky"};

		// Print the lengths of the arrays
        System.out.println(physicsLaureates.length + " physics laureates");
        System.out.println(literatureLaureates.____ + " literature laureates");
        System.out.println(____ + " chemistry laureates");
    }
}   	
Modifier et exécuter le code