A simple Baidu pen exam, a simple Baidu pen exam

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.