A simple Baidu pen exam, a simple Baidu pen exam
I. Introduction
I tried to make a Baidu pen exam, which is quite interesting. I posted it to share it with you.
Ii. Question
When I get lazy, I won't repeat it and paste it directly. Haha.
3. My Solutions
First of all, let's consider the programming language. I am most familiar with java, so let's write it in java.
My idea: the input is grouped, the first is n, and the second is m. Therefore, this can be used as the principle of data separation. Read the Code:
for(int i=1;i<args.length;i+=2){double n=Double.parseDouble(args[i-1]);double m=Double.parseDouble((args[i]));getResult(n, m);}
After obtaining n and m, you can consider the algorithm. Let's talk about the Code:
public static void getResult(double n,double m){double result=0;while(m--!=0){result+=n;n=Math.sqrt(n);}System.out.printf("%.2f\n",result);}
Well, it's good. It's just a few simple lines of code that contain a lot of knowledge points. I have to say that there are still a lot of basic knowledge.
Configure running parameters:
Running result:
94.73
3.41
121.57
Iv. complete code
/*** Project Name: CloudLibrary * File Name: TestDriver. java * Package Name: test * Date: September 16, 2015 10:04:54 * Copyright (c) 2015, winton_by@126.com All Rights Reserved. **/package test;/*** ClassName: TestDriver date: september 16, 2015 10:04:54 ** @ author winton_by@126.com * @ version v1.0 */public class TestDriver {public static void main (String args []) {for (int I = 1; I <args. length; I + = 2) {doub Le n = Double. parseDouble (args [I-1]); double m = Double. parseDouble (args [I]); getResult (n, m) ;}} public static void getResult (double n, double m) {double result = 0; while (m --! = 0) {result + = n; n = Math. sqrt (n);} System. out. printf ("%. 2f \ n", result );}}
5. Last sentence
Have everyone gotten along with each other? I think someone has a better solution. I hope you can give me some advice on how to make common progress and grow together.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger. QQ group: 372702757