Programming Literacy Day004

Posted by The_Anomaly on Sat, 12 Oct 2019 20:32:37 +0200

I. JavaScript Programming Problem

Enter a year (to be verified) on the page to determine whether it is a leap year (year divisible by 4, but not by 100; leap year divisible by 400), and display the corresponding prompt information on the page.
(1) Code

<!doctype html>
<html>
    <head>
        <title>Leap year</title>
        <meta charset="utf-8">
    </head>
    <body>
        <form>
            //Please enter the year: <input id="year" type="text"/>
            <text id="check"></text>
        </form>
        <script>
            var input = document.getElementById("year");
            var tip = document.getElementById("check");
            //Input Box Loss Focus Trigger Event
            input.onblur = function() {
                var year = input.value.trim();
                //Year consists of four digits
                if(/^\d{4}$/.test(year)) {
                    //A year divisible by four but not by 100; a leap year divisible by 400
                    if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
                        tip.innerHTML = "Leap year";
                    } else {
                        tip.innerHTML = "Non leap year";
                    }
                } else {
                    tip.innerHTML = "The format of the year is incorrect. Please re-enter it.";
                }
            }
        </script>
    </body>
</html>

(2) Operational screenshots

MySQL Questions and Answers

How do I log in to MySQL through a command prompt? How to list all databases? How to switch to a database and work on it? How to list all tables in a database? How do I get the names and types of all Field objects in the table?
Answer:

  1. mysql -u -p
  2. show databases;
  3. use dbname;
  4. show tables;
  5. describe table_name ;

3. Java programming problems

If a number is exactly equal to the sum of its factors, it is called a "perfect number". For example, 6 = 1 + 2 + 3. Programming finds all completions within 1000.
(1) Code

package com;

public class daily0801 {
	/**
	 * Judging whether it is a perfect number
	 * 
	 * @param a
	 *            Numbers to be judged
	 * @return boolean
	 */
	public static boolean test(int a) {
		int sum = 0;
		// Cyclic traversal, find all the factors, and calculate the sum of the factors
		for (int i = 1; i < a; i++) {
			if (a % i == 0)
				sum = sum + i;
		}
		return (sum == a);
	}

	public static void main(String[] args) {
		for (int i = 1; i < 1000; i++) {
			if (test(i)) {
				System.out.println(i);
			}
		}
	}

}

(2) Operational screenshots

Topics: MySQL Programming Database Javascript