Java programming question: The rules for a column of numbers are as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34… Find the 30th digit, and implement it using a recursive algorithm

/** * The rules for a column of numbers are as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34… Find the 30th digit, use recursive algorithm * */public class Test { public static void main(String[ ] args) { System.out.println(“The result is: “+Test.foo(30)); } /** * Recursive algorithm implementation */ public static int foo(int i){ if(i<=0) return 0; else if(i>0 && i<=2) return 1 ; return foo(i-1) + foo(i-2); }} The result is: 832040

[Java] Exercise 011: There are 1, 2, 3, and 4 numbers. How many different three-digit numbers can be formed without repeated numbers? How many are they? …

[Program11] Topics:are1、2、3、4 How many three-digit numbers that are different from each other and have no repeating digits can be formed by digits? 1.Program Analysis:The numbers that can be filled in the hundreds, tens and ones places are all1、2、3、4. After composing all the permutations, go to and delete the permutations that do not meet the conditions. import java.util.*;public class Test11{ public static void main(String[] args ) { int n; int count=0; Vector v = new Vector(); for(int i=1;i<=4;i++) { for(int j=1;j<=4;j++)                                                                                                                                          (int k=1;k<=4;k++)                                                                           =”#0000FF”>if(i!=k&&j!=k)                                                                       ; k; > } System.out.println(count); System.out.println(v); }} Transfer: https://blog.51cto.com/shylx123/554846

JAVA Programming 1. (Find the rules of 1,1,2,3,5,8,13,,,,,,)

1 package FushiExam; 2 import java.util.*; 3 public class Text_1 { 4 5 public static void main( String[] args) { 6 /* 7 * There is a pair of rabbits, from From the 3rd month after birth, a pair of rabbits are born every month. After the rabbit grows to the third month 8 * Another pair is born every month. A pair of rabbits. If the rabbits do not die, what is the total number of rabbits each month? 9 * That is, find the pattern of the first n numbers: 1 1 2 3 5 8 13…10 */11 //Fibonacci sequence problem12 Scanner scan=new Scanner(System.in);13 System.out.println(” Input number: “);14 int n=scan.nextInt(); 15 int first=1,secOnd=1,next;16 System.out .println(first);17 System.out.println(second);18 for(int i=3;i<=n;i++) {19 next=first+second;20 System.out.println(next);21 first= second;22 secOnd=next;23 } 24 25 26 }27 28 }

java11235_Use java to calculate the sum of the 120th digit of 1,1,2,3,5,8…

Use java to calculate the sum of the numbers 1, 1, 2, 3, 5, 8… 1-20th digits Attention: 254 Answer: 4 mip version Solution time 2021-01-27 00:01 The questioner is sorry and sorry 2021-01-26 16:29 Use java to calculate 1,1,2,3,5 ,8…The sum of the 1-20th digits Best answer Second-level knowledge expert Takaki Nono 2021-01-26 16:54 public class Test1 { public static void main(String args[]) { int a[] = new int[20]; a[0] = a[1] = 1; int sum = a[0] + a[1]; for (int i = 2; i <20; i++) { a[i] = a[i – 2] + a[i – 1]; sum += a[i]; } System.out.println(” The sum of the first 20 digits is :” + sum); } } The result is :17710 Answer all 1F Liuli Zhishi 2021-01-26 19:27 If you observe the rules of numbers, you will know that except for the first number And the second number is unexpected, the other numbers are equal to the first 2 numbers, and I wrote a function to see if you want to see it, but I didn’t pay much attention to the function name (I am a novice) //———– ——–Function class——————————— package com.yaojian.com; public class hanshu { public int feibulaji(int n){…

Java Joseph Ring Problem: It is known that n people (represented by numbers 1, 2, 3…n respectively) are sitting around a round table. Start counting from the person numbered k, and the person counting to m will come out of the queue; ArrayList implementation

Joseph Ring Problem – It is known that n people (represented by numbers 1, 2, 3…n respectively) are sitting around a round table. Start counting from the person numbered k – the person who counts to m comes out of the queue; the next person starts counting from 1 – the person who counts to m comes out of the queue again; follow this rule Repeat and output the number of the last remaining person. package com.temp;import java.util.ArrayList;import java.util.Scanner;public class JosephRingProblem {public static void main(String[] args) {// TODO Auto -generated method stubScanner scanner = new Scanner(System.in);System.out.println(“How many people are there in this round table?”);int n = scanner.nextInt();System .out.println(“How many people should I start counting from?”);int k = scanner.nextInt();k–;System.out.println(“How many people should I count from? The one dequeuing?”);int m = scanner.nextInt();ArrayList arrayList = new ArrayList();for(int i=1; i1) {System.out.println (arrayList);if(k+m<=len) {System.out.println("- –“+(k)+” “+m+” “+len);arrayList.remove((k+m-1)% len);k = (k+m-1)%len;}len–;}System.out.println(“The final winner is: “+arrayList.get( 0));}}

In javascript, why [1,2]+[3,4] is not equal to [1,2,3,4]?

Someone asked on stackoverflow: arrays – Why does [1,2] + [3,4] = “1,23,4” in Javascript? Question I want to append an array to the back of another array, so I wrote the following code in firebug: [1,2] + [3,4] However, unexpectedly, it output: “1,23,4” What I expected was not output: [1,2,3,4] What is going on? ? Why is [1,2] + [3,4] not equal [1,2,3,4]? Answer Javascript’s + operator has two goals: Add two numbers Add; Concatenate the two strings. The example does not define the behavior of the + operator on arrays, so Javascript first converts the array into a string, and then perform + operations on the string. If you want to connect two arrays, you can use the concat method of the array: [1, 2].concat([3, 4 ]) // [1, 2, 3, 4] Overview of the + operator in Javascript Javascript has 6 built-in data examples: ( Translation note: Judging from the connections given, the original author’s meaning should be the data type of the original type system. Javascript actually has two types of systems. The first type system uses typeof to identify it, called the primitive (primitive) paradigm system, and the second set of paradigm systems is based…

[Java Exercise] Output each digit of an integer, such as: each digit of 123 is 1, 2, 3

Learning objectives: Objectives:Proficiently use the knowledge learned in Java Question content: The content of this article:uses java language:to output each bit of an integer,such as& Each bit of #xff1a;123 is 1 , 2 , 3 Implementation Idea 1. First, store each bit of the integer in the array through the % remainder operation; 2. Read each bit of the array through a for loop, It can be spliced ​​with a string to output a string public <span class="token keywordclass practice {public static void main (String[] args) {Scanner scanner = new Scanner(System. in);int num = scanner.nextInt( );outPut(num);}private static void outPut(int num) {int[] a = new int[1000];//Array to store integersint i = 0; int count = 0;//Record how many digits the integer hasString s = ” “;while (num != 0) {a[i] &#61 ; num % 10;num = num / 10;i = i + 1;count++;}for (int j = count – 1; j >= 0; j–) {s = s + a[j]+ ” ,”;}System.out. println(s);}}//Output results23154122 ,3 ,1 , 5 ,4 ,1 ,2 ,Process finished with exit code 0

155158_RNWi_255456.png

2,JavaNIOOverview

2019 Unicorn Enterprises Recruit Python Engineer Standards with Large Money>>> Java NIO consists of the following core components: Channels Buffers Selectors Java NIO has more classes and components than these, but the Channel, Buffer and Selector forms the core of the API, in my opinion. The rest of the components, like Pipe and FileLock are merely utility classes to be used in conjunction with the three core components. Therefore, I’ll focus on these three components in this NIO overview. The other components are explained in their own texts elsewhere in this tutorial. See the menu at the top corner of this page. Channels and Buffers Typically, all IO in NIO starts with a Channel. A Channel is a bit like a stream. From the Channel data can be read into a Buffer. Data can also be written from a Buffer into a Channel. Here is an illustration of that: Java NIO: Channels read data into Buffers, and Buffers write data into Channels There are several Channel and Buffer types. Here is a list of the primary Channel implementations in Java NIO: FileChannel DatagramChannel SocketChannel ServerSocketChannel As you can see, these channels cover UDP & #43; TCP network IO, and file…

Java classic algorithm_011 has 1, 2, 3, and 4 numbers. How many different three-digit numbers can be formed without repeated numbers? How many are they?

Question: There are 1, 2, 3, and 4 numbers. How many different three-digit numbers can be formed without repeated numbers? How many are they? package com.arithmetic;/** * Question: There are 1, 2, 3, and 4 numbers. How many different numbers can be formed? The same three-digit number without repeating digits? How many are they? * * @author Administrator * */public class Test_wzs11 {public static void main(String[] args) {int temp = 0;for (int i = 1; i <= 4; i++) {for (int j = 1; j <= 4; j++) {for (int k = 1; k <= 4; k++) {if (i != j && j != k && i != k) {temp = i * 100 + j * 10 + k;System.out.print(temp + “,”);}}}}}}

PHP array, how does $a={0,1,2,3} become $a={1,2,3,4]

PHP array, how does $a={0,1,2,3} become $a={1,2,3,4]

PHP array, how does $a = {0,1,2,3} become $a = {1,2,3,4]PHP array, how does $a = {0,1,2,3} change becomes $a = {1,2,3,4]. It is the dimension of the multi-dimensional array, and then adds 1 to the dimension and outputs it as the sequence number of the table, 1, 2, 3, 4——Solution—- —————- $a = array(0, 1, 2, 3); $b = range(1, count($a)); $c = array_combine($b, $a); print_r($c); Array ( [1] => 0 [2] => 1 [3] => 2 [4] => 3 ) ——Solution——————– $arr = array(0,1,2,3); $temp = array(); foreach($arr as $k=>$v){ $k++; $temp[] = $k; } print_r($temp); The moderator’s is prettier! ——Solution—— —————The moderator’s idea is beautiful, and here is another idea. <?php $a = array(0,1,2,3); array_unshift($a, 0); // Insert a new element at the beginning of the array to increase the key by 1 unset($a[0]); // Delete the newly added elements at the beginning, but the key remains unchanged print_r($a);                        // Output ?>

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索