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

Insert image description here

Use Java simulation to implement disk array raid levels 0, 1, 3, 5, 6, 01, 10

Table of contents 1. Instructions for use 2. Overall design 3. Operation screenshots 4. Detailed design 4.1raid0 4.2raid1 4.3raid3 4.4raid5 4.5raid6 4.6raid01 4.7raid10 5. Source code 1. Instructions for use The development environment of this program is the Windows operating system Eclipse software – developed using Java language. When using, open the project file and run Main.java under the raidMain package. According to the prompts, enter the file to be written “full path of the file” and the file to be read. The entered file path indicates file reading. The saved path “contains the file name to be read” and the file can be restored. The disk “folder” used by each disk array level data is different. For example, the main disk path of raid0 is disk/raid0 and raid6 is disk/raid6. The other disk/read and disk/read are used to demonstrate the file path for writing and reading. Of course, you can also choose other files for operation. Data when the disk is damaged when raid3, 5, and 6 are not completed. Restoration: After writing, I still found that there were still big problems with the program structure. However, the changes took a lot of time and I just let it…

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){…

How to implement php to arrange in the order of 1, 2, 3 or 4, 5, solve

How to arrange php in the order of 1, 2, 3 or 4, 5? The solution is if there is a string of numbers 1, 2, 3, 7, 8, how can 123 be divided into a group, let’s say 7, 8 Assign to another group, that is, separate 1, 2, 3 and 7.8——Solution Idea————– ——– $s = ‘1, 2, 3, 7, 8’;$ar = explode(‘ ,’, $s);$arr = array();foreach($ar as $v){ $c = count($arr); if( $v == 1 ——Solution Idea———————- ($v != end($arr[$c-1]) +1)){ $arr[][] = $v; }else{ $arr[$c-1][] = $v; } }print_r($arr); Array( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [1] => Array ( [0] => 7 [1] => 8 ) )——Solution Idea———————- <?php $s = ‘1, 2, 3, 7, 8’; $ar = explode(‘,’, $ s); $arr = array(); foreach($ar as $v){ $c = count($arr); if($v == 1 ——Solution Idea———————- ($v != end($arr[$c-1]) +1)){ $arr[][] = $v; }else{ $arr[$ c-1][] = $v; } } $One= implode(‘,’,$arr[0]); $two = implode(‘,’,$arr[1]); echo “First winning streak:”.$one; echo “”; echo “Second winning streak:”.$two;?> Run results: First winning streak :1,2,3Second winning streak: 7,8

How does php realize the order of 1, 2, 3 or 4, 5, and solve

That is, if there is a string of numbers 1, 2, 3, 7, 8, how can we divide 123 into one group, let 7, 8 be divided into another group, that is, separate 1, 2, 3 and 7.8 4 solutions #1 What is the rule for grouping, 3 in the first group and 2 in the second? #2 Quoting the reply of jordan102 on the 1st floor: What is the rule for grouping, 3 in the first group and 2 in the second? This is not limited, it is just an example. It is a quiz winning streak record. Arrange it. If you guess three times in a row, record the id of these three times. day id #3 $s = ‘1, 2, 3, 7, 8’; $ar = explode(‘,’, $s); $arr = array(); foreach($ar as $v){ $c = count($arr); if($v == 1 || ($v != end($arr[$c-1]) +1)){ $arr[][] = $v; }else{ $arr[$c-1][] = $v; } } print_r($arr); Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [1] => Array ( [0] => 7 [1] => 8 ) ) #4 <?php $s = ‘1, 2, 3, 7, 8’; $ar = explode(‘,’, $s); $arr =…

How does the php array elegantly convert 1,2,4,5,6,7,9,11 into strings like ‘1,2,47,9,11’?

As the title There is a php array 1234 [1,2,4,5, 6,7,9,11] [7,11,16,17,18,33,102,103,555] Elegant conversion to 12 ‘1,2,4-7,9, 11’ ‘7,11,16-18,33,102-103,555’ like this What about strings? Thank you for your answer.

Can MFC display ASCII codes of 3, 4, 5, and 6 symbols (suit symbols of playing cards)

The symbols of the four suits of playing cards are required, but the characters within ASCII code 32 are undisplayable characters, which can be printed under the console program. as follows: #includeusing namespace std ;int main(){ cout<<char(3)<< endl; cout<<char(4)<<endl; cout<<char(5)<<endl; cout<<char(6)<<endl; getchar(); return 0;} But I can’t find the characters whose ASCII codes are 3, 4, 5, and 6 that can be displayed in MFC. Ask for advice. . 20 solutions #1 This depends on the mode of your machine, system, and monitor. For example, cmd is different from traditional dos. #2 #include “stdafx.h” int main(int argc, char* argv[]) { printf(“%c %c %c %c!\n”,3, 4 ,5, 6); return 0; } It can be displayed under my win7 + vc6 console, but it may not work after posting it. ! Press any key to continue #3 What I’m talking about is whether these characters can be output in MFC. . Continue to ask. . #4 Continue to ask. . #5 #includeusing namespace std ;int main(){ cout<<char('0' + 3)<<endl; cout<<char('0' + 4)<<endl; cout<<char('0' + 5)<<endl; cout<<char( '0' + 6)<<endl; getchar(); return 0;} #6 Quoting the reply of yuucyf on the 5th floor: C/C++ code #include using namespace std ; int main() {…

underscore knowledge points_error: partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,_cily_undefined’s blog

1. Installation Node. js –> npm install underscore Meteor.js –> meteor add underscore Require.js –> require([“underscore”], … Bower bower –> install underscore Component –> component install jashkenas/underscore Second, aggregate function (array or object) 1, each Syntax: _.each(list, iteratee, [context]) Description: Traverse all elements in the list, and call the iteratee function with each element as a parameter in order. If the context parameter is passed, bind iteratee to the context object. Each call to iteratee passes three parameters: (element, index, list). If list is a JavaScript object, the arguments to iteratee are (value, key, list)). Return a list to facilitate chain calls. Example: _.each([1, 2, 3], alert); => alerts each number in turn… _.each({one: 1, two: 2, three: 3}, alert); => alerts each number value in turn… 2, map Syntax: _.map(list, iteratee, [context]) Description: Generate a corresponding array by calling the conversion function (iteratee iterator) for each element in the list. iteratee passes three parameters: value, then the iteration index (or key Fool’s Wharf note: if the list is a JavaScript object, this parameter is the key), and the last one is a reference to the entire list. Example: _.map([1, 2, 3], function(num){ return num * 3; }); => [3,…

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
首页
微信
电话
搜索