Question: Help with this java word game...have one error cannot figure out why... WordGame.java:23: error: incompatible types: String cannot be converted to int age = scanner.nextLine();

Help with this java word game...have one error cannot figure out why... WordGame.java:23: error: incompatible types: String cannot be converted to int age = scanner.nextLine(); ^ 1 error - the carrot symbol is by the () on scanner.nextLine.

1 import java.util.Scanner;

2

3 public class WordGame {

4

5 public static void main( String [] args ) {

6

7 // create a scanner object

8 Scanner scanner = new Scanner( System.in );

9

10 // declare variables

11 String name;

12 int age;

13 String city;

14 String college;

15 String profession;

16 String animal;

17 String petName;

18

19 System.out.print(" Please enter your name: ");

20 name = scanner.nextLine();

21

22 System.out.print( "Please enter your age: ");

23 age = scanner.nextLine();

24

25 System.out.print( "Please enter your city: ");

26 city = scanner.nextLine();

27

28 System.out.print( "Please enter your college: ");

29 college = scanner.nextLine();

30

31 System.out.print( "Please enter your profession: ");

32 profession = scanner.nextLine();

33

34 System.out.print( "Please enter a type of animal: ");

35 animal = scanner.nextLine();

36

37 System.out.print( "Please enter the name of your pet name: ");

38 petName = scanner.nextLine(); 39

40 //Display Story

41

42 System.out.println( "There was once a person named " + name + "who lived in " + city + ". At the age of " + age + "," +

43 name + " went to college at" + college + "." + name + " graduated and went to work as a " +

44 profession + ". Then, " + name + " adopted a(n) " + animal + " named " + petName + ". They both lived " +

45 " lived happily ever after!" );

46 }

47 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!