Write a program that reads a person\'s age then display its category according t
ID: 3779392 • Letter: W
Question
Write a program that reads a person's age then display its category according to the table: Write a program that reads an integers x and a positive integer y, and prints x^y in three different scenario: Using For loop Using while loop Using Do-While loop The idea: x^y = x * x *...* x y times Plan: we need to repeat some action y times the action is to multiply x with previous result Don't forget to initialize the result to 1 Write a program to read an integer x, and tell whether it is prime or not using for loop.Explanation / Answer
The answer to the 1st question is as follows:
package test;
import java.io.*;
import java.util.*;
public class test1 {
public static void main(String[] args) {
int age;
Scanner sc=new Scanner(System.in);
System.out.println("What is your age?");
age=sc.nextInt();
if(age<2)
{
System.out.println("Baby");
}
if(age>=2 && age<12)
{
System.out.println("Child");
}
if(age>=12 && age<18)
{
System.out.println("Teen");
}
if(age>=18)
{
System.out.println("Adult");
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.