30 likes | 128 Views
Test your coding skills by finding and fixing 5 mistakes in the given Java code. Learn proper coding practices and improve your programming accuracy.
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.