We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
every thing is okk ............ last new line is thowing erroer
importjava.io.*;importjava.util.*;publicclassPerson{privateintage;publicPerson(intinitialAge){// Add some more code to run some checks on initialAgeif(initialAge<=0){System.out.println("Age is not valid, setting age to 0");this.age=0;}else{this.age=initialAge;}}publicvoidamIOld(){// Write code determining if this person's age is old and print the correct statement:if(this.age<13){System.out.println("You are young");}if(this.age>=13&&this.age<18){System.out.println("You are a teenager");}elseif(this.age>=18){System.out.println("You are old");}}publicvoidyearPasses(){// Increment this person's age.this.age+=1;}publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intT=sc.nextInt();for(inti=0;i<T;i++){intage=sc.nextInt();Personp=newPerson(age);p.amIOld();for(intj=0;j<3;j++){p.yearPasses();}p.amIOld();System.out.println();}sc.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 4: Class vs. Instance
You are viewing a single comment's thread. Return to all comments →
every thing is okk ............ last new line is thowing erroer