30 likes | 118 Views
Spot the mistakes!. public class PetAge { public static void main(String[] args ) { String petname ; boolean petage ; petname = Rollo ; potage = 6 ; System.out.println ("My pet's name is " + petname ) System.out.println ( petname +" is "+ petage + " years old ." ; } }
E N D
Spot the mistakes! public class PetAge { public static void main(String[] args) { String petname; booleanpetage; petname = Rollo; potage= 6; System.out.println("My pet's name is " + petname) System.out.println(petname+" is "+ petage+ " years old."; } } Hint: there are 5 of them
Answers. Data type should be int not boolean. A String should have speech marks. Variable names should always be spelled the same. There should always be a semi colon at the end of a line of code. Brackets that are opened must be closed. public class PetAge { public static void main(String[] args) { String petname; booleanpetage; petname = Rollo; potage= 6; System.out.println("My pet's name is " + petname) System.out.println(petname+" is "+ petage+ " years old."; } } Well done if you found them all.
Correct code. public class PetAge { public static void main(String[] args) { String petname; intpetage; petname = "Rollo"; petage= 6; System.out.println("My pet's name is " + petname); System.out.println(petname+" is "+ petage+ " years old."); } } Remember to be precise when writing your code.