Given an integer age, print on the screen:
Do not change the case of any letter in "Adult" and "Teen" while printing the answer.
For printing use:-
Input: age = 19
Output: Adult
Explanation: age is greater than or equal to 18.
Input: age = 7
Output: Teen
Explanation: age is less than 18.
Input: age = 18
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
/* Function to check if the person
in an adult or a teen */
void isAdult(int age) {
// If age is greater than 18
if (age >= 18) {
// The person is an adult
cout << "Adult";
}
// Otherwise
else {
// The person is a teen
cout << "Teen";
}
}
};
int main() {
// Creating an instance of Solution class
Solution solution;
//Take age as input
int age;
cout << "Enter your age: ";
cin >> age;
/* Function call to check if the person
in an adult or a teen */
solution.isAdult(age);
return 0;
}
import java.util.Scanner;
class Solution {
/* Function to check if the person
is an adult or a teen */
public void isAdult(int age) {
// If age is greater than or equal to 18
if (age >= 18) {
// The person is an adult
System.out.print("Adult");
}
// Otherwise
else {
// The person is a teen
System.out.print("Teen");
}
}
}
class Main {
public static void main(String[] args) {
// Creating an instance of Solution class
Solution solution = new Solution();
// Take age as input
Scanner sc = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = sc.nextInt();
/* Function call to check if the person
is an adult or a teen */
solution.isAdult(age);
}
}
class Solution:
''' Function to check if the person
is an adult or a teen '''
def isAdult(self, age):
# If age is greater than or equal to 18
if age >= 18:
# The person is an adult
print("Adult")
# Otherwise
else:
# The person is a teen
print("Teen")
if __name__ == "__main__":
# Creating an instance of Solution class
solution = Solution()
# Take age as input
age = int(input("Enter your age: "))
''' Function call to check if the person
is an adult or a teen '''
solution.isAdult(age)
class Solution {
/* Function to check if the person
is an adult or a teen */
isAdult(age) {
// If age is greater than or equal to 18
if (age >= 18) {
// The person is an adult
console.log("Adult");
}
// Otherwise
else {
// The person is a teen
console.log("Teen");
}
}
}
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
// Creating an instance of Solution class
const solution = new Solution();
// Take age as input
readline.question('Enter your age: ', age => {
/* Function call to check if the person
is an adult or a teen */
solution.isAdult(parseInt(age));
readline.close();
});
Time Complexity: O(1), The operations of receiving input and printing output are executed once regardless of the size of the input.
Space Complexity: O(1), Using only a single variable to store the age, and no other additional space is used that grows with the input size.