Sort by

recency

|

1892 Discussions

|

  • + 0 comments

    I think my solution it's ok, a blank line is being printed at the end of execution but I'm not allowed to modify that code and because of that I think the outcome is a "wrong" answer, please let me know if you see something wrong with my solution

    process.stdin.resume();
    process.stdin.setEncoding('ascii');
    
    var input_stdin = "";
    var input_stdin_array = "";
    var input_currentline = 0;
    
    process.stdin.on('data', function (data) {
        input_stdin += data;
    });
    
    process.stdin.on('end', function () {
        input_stdin_array = input_stdin.split("\n");
        main();    
    });
    
    function readLine() {
        return input_stdin_array[input_currentline++];
    }
    function Person(initialAge) {
      this.age = initialAge;
      if (this.age < 0) {
          this.age = 0;
          console.log("Age is not valid, setting age to 0.");
      }
        // Add some more code to run some checks on initialAge
        this.amIOld=function(){
                // Do some computations in here and print out the correct statement to the console
                if (this.age < 13) {
                    console.log("You are young.");
                } else {
                    if ( this.age < 18) {
                        console.log("You are teenager.");
                    } else {
                        console.log("You are old.");
                    }
                }
        };
       this.yearPasses=function(){
              // Increment the age of the person in here
              this.age++;
       };
    }
    
    
    function main() {
    
    var T=parseInt(readLine());
    for(i=0;i<T;i++){
        var age=parseInt(readLine());
        var p=new Person(age);
        p.amIOld();
        for(j=0;j<3;j++){
            p.yearPasses();
            
        }
        p.amIOld();
        console.log("");   
        }
    }
    
  • + 0 comments

    the code doesn't print the you are old statement what could be the reason` import java.io.; import java.util.;

    public class Person { private int age;

    public Person(int initialAge) {
        // Add some more code to run some checks on initialAge
    
         if(initialAge>0){
              age=initialAge;
    
    
          }
          else{
    
            System.out.println("Age is not valid, setting age to 0.");
              this.age=0;
          }
    
    }
    
    public void amIOld() {
        // Write code determining if this person's age is old and print the correct statement:
          if(age<13)
          {
              System.out.println("You are young..");
          }
          else if(age>=13 && age<28)
          {
              System.out.println("You are a teenager..");
          }
          else if(age >=18)
          {
              System.out.println("You are old..");
        }
    
    }
    
    public void yearPasses() {
        // Increment this person's age.
          this.age=age++;
    }
    
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int i = 0; i < T; i++) {
            int age = sc.nextInt();
            Person p = new Person(age);
            p.amIOld();
            for (int j = 0; j < 3; j++) {
                p.yearPasses();
            }
            p.amIOld();
            System.out.println();
        }
        sc.close();
    }
    

    } `

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Person {
        private int age;	
      
    	public Person(int initialAge) {
      		// Add some more code to run some checks on initialAge
              
              if(initialAge>0){
                  age=initialAge;
                //   System.out.print("Age is not valid, setting age to 0.");
                //   this.age=0;
                  
              }
              else{
                //   this.age=initialAge;
                System.out.println("Age is not valid, setting age to 0.");
                  this.age=0;
              }
    	}
    
    	public void amIOld() {
      		// Write code determining if this person's age is old and print the correct statement:
            // System.out.print(/*Insert correct print statement here*/);
            if(age<13 ){
                System.out.print("You are young.\n");
            }
            if(age>=13 && age<18){
                System.out.print("You are a teenager.\n");
            }
            if(age>=18){
                System.out.print("You are old.\n");
            }
    	}
    
    	public void yearPasses() {
      		// Increment this person's age.
              age++;
    	}
    
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int T = sc.nextInt();
    		for (int i = 0; i < T; i++) {
    			int age = sc.nextInt();
    			Person p = new Person(age);
    			p.amIOld();
    			for (int j = 0; j < 3; j++) {
    				p.yearPasses();
    			}
    			p.amIOld();
    			System.out.println();
            }
    		sc.close();
        }
    }
    
  • + 1 comment

    This is broken for Typescript!

  • + 0 comments

    Guys! this is my code what am i doing wrong? public class Solution {

    public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
    int T = sc.nextInt();
    for (int i = 0; i < T; i++) {
        int age = sc.nextInt();
        Person p = new Person();
        p.amIOld(age);
        for (int j = 0; j < 3; j++) {
            p.yearPasses();
        }
        p.amIOld();
        System.out.println();
    }
    sc.close();
    

    } /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ public class Person { private int age;

      public Person(int initialAge){
          if (initialAge > 0) {
               this.age = age;
          } else if (initialAge < 0){
              this.age = 0;
              System.out.println("Age is not valid, settimg age to 0");
          }
      }
    

    public void yearPasses(){ age = age + 1; } public void amIOld() { if(age < 13) { System.out.println("You are young..");
    }

    else if(age >= 13 && age < 18) {
        System.out.println("You are a teenager");
    } 
    else {
        System.out.println("You are old..");
    }
    
    }
    }