Bonjour,
Ce programme demande d'entrer un chiffre (nombre d'animaux), puis d'introduire dans un tableau des strings les especes : cheval, chien, chat...
Mais j'ai une erreur au début...
Merci...
import java.util.Scanner;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public class Animal { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Donner le nombre des animaux :"); int nbAnim = sc.nextInt(); String []tab1 = new String [nbAnim]; for (int i = 0; i < tab1.length; i++) { System.out.println("Saisir espece " + (i+1)); tab1[i] = sc.nextLine(); } for (int i = 0; i < tab1.length; i++) { System.out.println("Animal "+ (i+1) +" = "+ tab1[i]); } }
Partager