Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Java five novice training


May 28, 2021 Article blog


Table of contents


Java's training topics are thousands of, with topics to exercise is the best choice, this article provides you with five of the most popular topics.

First, according to the age range output age

Topics are required for adolescents (less than 18 years of age), young people (19-28), middle-aged (29-55), and old age (56 or older)

import java.util.Scanner;

 public static void main0(String[] args) {

        Scanner scan = new Scanner(System.in);

        System.out.print("请输入这个人的年龄大小:");

        int age = scan.nextInt();

        if(age>=0 && age<=18){
            System.out.println("少年");
        }
        else if(age>=19 && age<=28){
            System.out.println("青年");
        }
        else if(age>=29 && age<=55){
            System.out.println("中年");
        }
        else if(age>=56){
            System.out.println("老年");
        }
    }

Compilation effect:

 Java five novice training1

Second, print 1-100 prime number

 public static void main(String[] args) {
        int i=1;
        int j=2;
        int count=0;
        for(i=1;i<=100;i++){

            for(j=2;j<i;j++){
                if (i%j==0){
                    break;
                }
            }
            if(i==j){
                System.out.println(i);
                count++;
            }
        }
        System.out.println(count);
    }

Compilation effect:

 Java five novice training2

Third, judge the prime number

Enter a random number to determine if it is prime

 import java.util.Scanner;
 public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.printf("请输入要判断的数字:");
        int num=scan.nextInt();
        int i=0;
        for( i=2;i<num;i++){
            if(num%i==0){
                System.out.println(num+"不是素数");
                break;
            }
        }
        if(i==num){
            System.out.println(num+"是素数");
        }
    }

Compilation effect:

 Java five novice training3

Fourth, output leap year

Make it output all leap years in 1000-2000


public static void main(String[] args) {
        int count = 0;
        for(int year=1000;year<=2000;year++){

            if((year%4==0) && (year %100!=0) ||(year %400 == 0) ){

                System.out.println(year);
                count++;
            }
        }
        System.out.println(count);

    }

Compilation effect:

 Java five novice training4

V. Multiplication tips table

Make it a multiplication table of 9x9

public static void main(String[] args) {

        for(int i=1;i<10;i++){

            for(int j=1;j<=i;j++){
                System.out.printf("%d*%d=%-2d  ",j,i,i*j);
            }
            System.out.println();
        }
    }

Compilation effect:

 Java five novice training5

That's all you need to do with java's five novice trainings.