Hi guys, I know I haven’t been posting for a while, so I’m going to start fresh with a few small java projects, like this one that I’ve just made, a machine that takes your age and gives you which stage of life you’re in.

				
					import java.util.Scanner;
public class Main {
        public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
       
        System.out.print("What's your name? ");
        String userName = input.nextLine();
        System.out.print("What's your age? ");
        int userAge = input.nextInt();

        if (userAge >= 90) {
            System.out.println(userName + " is extremely old.”);
        } else if (userAge >= 70) {
            System.out.println(userName + " is a grandpa.");
        } else if (userAge >= 55) {
            System.out.println(userName + " is an old adult.");
        } else if (userAge >= 35) {
            System.out.println(userName + " is an adult.");
        } else if (userAge >= 18) {
            System.out.println(userName + " is a young adult.");
        } else if (userAge >= 13) {
            System.out.println(userName + " is a teenager.");
        } else if (userAge >= 6) {
            System.out.println(userName + " is a child.");
        } else {
            System.out.println(userName + " is a baby.");
        }
    }
}
				
			

To use this code is extremely simple. The steps are listed below, but the simple version is: Copy code, paste in an online compiler, run, and answer any questions the program gives you.

HOW TO USE (Step-by-Step)

1. First, you need to copy the code. Hover over the code, and a small “Copy” button will appear in the top-right. Copy the code with the button. If it’s not showing up, you can also highlight the code and copy it manually.

2. Next, you have to go to an online Java compiler. Programiz compiler is highly recommended, as that is where I build my code.

3. In the left panel, remove all the code that Programiz already has there by default, and paste my code in.

4. Click run, and your program should automatically run. Fill in any questions it asks you on the right panel.

Using the code is that simple! Every day, I’m going to post another one of these simple programs for a few days. Make sure to check in tomorrow for the next simple program, and have a good day!

Leave a Reply

This Site Uses WPStatistics!

WPStatistics is a site view tracker that is GDPR, CCPA, PECR, and cookie compliance by default.