forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise8F.java
More file actions
35 lines (25 loc) · 786 Bytes
/
Copy pathExercise8F.java
File metadata and controls
35 lines (25 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Arrays;
import java.util.Scanner;
public class Exercise8F
{
public static void main(String[] args)
{
petNames();
}
private static void petNames()
{
Scanner in = new Scanner(System.in);
System.out.println("How many pets do you have? ");
int numberOfPets = in.nextInt();
in.nextLine();
String[] petNames = new String [numberOfPets];
int currentPet = 0;
while (currentPet < numberOfPets)
{
System.out.println("What is the name of pet number " + (currentPet + 1) + "? ");
petNames [currentPet] = in.nextLine();
currentPet++;
}
System.out.println("The names of your pets are" + Arrays.toString(petNames) + ".");
}
}