search
HomeJavaJavagetting Startedwhat is java algorithm

what is java algorithm

Feb 03, 2020 am 11:45 AM
javaalgorithm

what is java algorithm

What is java algorithm

Algorithm refers to an accurate and complete description of the problem-solving solution, which is a series of methods to solve the problem. Clear instructions, java algorithm is to use Java language to implement clear instructions to solve a certain problem.

Characteristics of the algorithm:

Input property: There are zero or more external quantities as input to the algorithm

Output property: Algorithm Produce at least one quantity as output

Deterministic: Each instruction in the algorithm is clear and unambiguous

Finiteness: The number of executions of each instruction in the algorithm is limited, and the execution of each instruction is time Also limited

Feasibility: The algorithm can run accurately in principle, and people can complete it after doing a limited number of operations with paper and pen.

Program: The algorithm uses a specific programming language Implementation, the program does not need to meet the four criteria of the exhaustive

algorithm:

Correctness: Under reasonable data input, it can be obtained within a limited time Correct results

Readability: It should be easy for humans to understand and debug

Robustness: The ability to check for errors and handle them appropriately

Efficiency: Algorithm The amount of computer resources required for execution, including running time and storage space

The description form of the algorithm: 1. Natural language 2. Algorithm block diagram method 3. Pseudo code language 4. High-level programming language

The general process of algorithm design:

1. Understand the problem

2. Predict all possible inputs

3. Between exact solution and approximation Choosing between solutions

4. Determining the appropriate data structure

5. Algorithm design technology

6. Describing the algorithm

7. Tracking algorithm

8. Analyze the efficiency of the algorithm

9. Write code according to the algorithm

The following is an algorithm implemented in Java: Bubble sort

/**
 * 冒泡排序
 */
public class BubbleSort1 {
    public static void BubbleSort(int[] arr) {
        boolean flag = true;
        while(flag){
            int temp;//定义一个临时变量
            for(int i=0;i<arr.length-1;i++){//冒泡趟数,n-1趟
                for(int j=0;j<arr.length-i-1;j++){
                    if(arr[j+1]<arr[j]){
                        temp = arr[j];
                        arr[j] = arr[j+1];
                        arr[j+1] = temp;
                        flag = true;
                    }
                }
                if(!flag){
                    break;//若果没有发生交换,则退出循环
                }
            }
        }
    }
    public static void main(String[] args) {
        int arr[] = new int[]{1,6,2,2,5};
        BubbleSort.BubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}

Related article tutorial recommendations: java introductory tutorial

The above is the detailed content of what is java algorithm. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.