Write a program that reads a persons age then display its ca
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.
Solution
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\");
}
}
}
