当前位置:网站首页>Using recursive method to find the value of 1~n
Using recursive method to find the value of 1~n
2022-06-25 21:22:00 【vancomycin】
package com.qfedu.test;
import java.util.Scanner;
// Recursive search 1~n Value
public class Test3 {
public static int getsum(int n) {
if (n==1) {
return 1;// Recursion ends
}
int temp = getsum(n-1);
return temp+n;
}
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println(" Please enter an integer :");
int num = input.nextInt();
int sum= getsum(num);
System.out.println("sum="+sum);
}
}边栏推荐
- JVM Foundation
- OBD Position Overview
- Is it legal to open an account for flush stock trading software? Is it safe?
- The robot framework calls the JS interface and gets the return value
- Is it safe for qiniu school to open a securities account?
- What is a subnet mask? (Powercert animated videos)
- Openocd adds third-party device support: ht32f52352 Cortex-M0+
- [opencv] opencv from introduction to mastery -- detailed explanation of input and output XML and yaml files
- Install JDK, MySQL and nexus under Linux (tar package installation)
- [summary] 2021unctf Campus (cry & MISC)
猜你喜欢

Jmeter- (II) basic interface and common components for interface testing

IPv4 and IPv6 (powercert animated videos)

Jingxi Pinpin wechat applet -signstr parameter encryption

XMIND to excel test case
![[nail scenario capability package] hospital visitor verification](/img/0e/43433ca5586c48d01708e5fa39a808.jpg)
[nail scenario capability package] hospital visitor verification

Decryption of APP parameters of a cross-border export e-commerce - dunhuang.com

Canoe learning notes (2)

How testers write functional test cases

Rounding related calculation

UDP Vs TCP (Powercert animated videos)
随机推荐
How testers write functional test cases
Alicloud disk mounted locally
Cross project measurement is a good helper for CTOs and PMOS
The beginning of manjaro's journey
Send a more awesome website, which can convert curl commands into code in any language
银河证券靠谱吗?开证券账户安全吗?
The robotframework executes CMD commands and bat scripts
Order by keyword syntax problems encountered in SQL Server learning
[opencv] opencv from introduction to mastery -- detailed explanation of input and output XML and yaml files
js(3)
Beginner to embedded development
A simple file searcher
IPv4 and IPv6 (powercert animated videos)
Dbeaver offline installation driver
What is machine learning? (Fundamentals)
What is a subnet mask? (Powercert animated videos)
Get parameters in URL
On ACM competition
Openocd adds third-party device support: ht32f52352 Cortex-M0+
MySQL trigger