In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the simple programming algorithm problems for Java beginners", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the simple programming algorithm problems for Java beginners"?
I. Preface
How close is math to programmers?
Whether ifelse or for loop, the code can be said to be the concrete implementation of mathematical logic. So programmers who type the code are almost inseparable from mathematics, it's just that it's different.
Can't you write code if you're not good at math? No, you can also write code, you can write more CRUD. Then you should not always think that the product requirements are simple, so your implementation process has become add, delete, change and query, often because you do not have the ability to implement scalable, easy-to-maintain, high-performance code implementation, which makes you write more CRUD at a young age!
Compared with small workshops bought and sold by awl, large and super factories pay more attention to math ability.
In 2004, a huge billboard suddenly appeared on Highway 101, the traffic artery in Silicon Valley, with a math problem: the first 10 prime digits of e. Com.
Advertisement: e here is a mathematical constant, the base of natural logarithm, infinitely non-cyclic decimal. The meaning of this question is to find out the first 10 prime numbers in e, and then you can get a web address. If you go to this site, you will see the second math problem given by Google. Google will tell you that we may be "like-minded" people, you can send your resume to this email, and we can do something to change the world together.
The e value can be calculated by Taylor formula: e ^ x ≈ 1 + x + x ^ 2 / 2! + x ^ 3 / 3! +. + x ^ n / n! (1) the derivation and calculation process also includes the use of Eratosthenes screening method (the Sieve of Eratosthenes) and linear screening method. Interested partners can be implemented in code.
Second, programming exercises 1. Fibonacci series @ Testpublic void test_Fibonacci () {int month = 15; / 15 months long F1 = 1L, f2 = 1L; long f; for (int I = 3; I
< month; i++) { f = f2; f2 = f1 + f2; f1 = f; System.out.println("第" + i + "个月的兔子对数: " + f2); }} 难度:⭐⭐⭐⭐⭐ 题目:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 逻辑:F(0)=0,F(1)=1, F(n)=F(n - 1)+F(n - 2) 扩展:斐波那契数列(Fibonacci sequence),又称黄金分割数列,因数学家莱昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,故又称为"兔子数列",指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、……在数学上,斐波那契数列以如下被以递推的方法定义:F(0)=0,F(1)=1, F(n)=F(n - 1)+F(n - 2)(n ≥ 2,n ∈ N*)在现代物理、准晶体结构、化学等领域,斐波纳契数列都有直接的应用,为此,美国数学会从 1963 年起出版了以《斐波纳契数列季刊》为名的一份数学杂志,用于专门刊载这方面的研究成果。 2. 判断素数@Testpublic void test_Prime() { int count = 0; for (int i = 101; i < 200; i++) { boolean b = true;// 默认此数就素数 for (int j = 2; j k && n % k != k++; f(n); break; } }} 难度:⭐⭐⭐⭐ 题目:将一个正整数分解质因数。例如:输入90,打印出90=233*5。 逻辑:对n进行分解质因数,应先找到一个最小的质数k,然后按此步骤完成(1)如果这个质数恰等于n,则说明分解质因数的过程已经结束,打印出即可。(2)如果n>K, but n is divisible by k, then you should print out the value of k and divide n by the quotient of k as the new positive integer you n, repeat the first step. (3) if n is not divisible by k, the first step is repeated by using kapp1 as the value of k.
Expansion: each composite number can be written in the form of the multiplication of several prime numbers, in which each prime number is the factor of the composite number, and a composite number is expressed in the form of prime factor multiplication, which is called decomposition prime factor. Such as 302 × 3 × 5. The decomposition prime factor is only for composite numbers.
5. Yang Hui Triangle @ Test public void test_YangHuiSanJiao () {int [] [] a = new int [10] [10]; for (int I = 0; I
< 10; i++) { a[i][i] = 1; a[i][0] = 1; } for (int i = 2; i < 10; i++) { for (int j = 1; j < i; j++) { a[i][j] = a[i - 1][j - 1] + a[i - 1][j]; } } for (int i = 0; i < 10; i++) { for (int k = 0; k < 2 * (10 - i) - 1; k++) { System.out.print(" "); } for (int j = 0; j c) { int t = a; a = c; c = t; } if (b >C) {int t = b; b = c; c = t;} System.out.println (a + "" + b + "+ c);} public int input () {int value = 0 Scanner s = new Scanner (System.in); value = s.nextInt (); return value;} public void compare (int x, int y) {/ / this method does not use if (x > y) {int t = x; x = y Y = t;}}
Difficulty: ⭐⭐
Topic: enter three integers x _ # y ~ z, please output these three numbers from small to large.
Logic: the method puts the minimum number on x, first compares x with y, if x > y, swaps the values of x and y, and then compares x with z, and if x > z, swaps the values of x and z, which minimizes x.
13. Monkey eating peach problem public class Monkey {public static void main (String [] args) {int lastdayNum = 1; for (int I = 2; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.