当前位置:网站首页>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);
}
}边栏推荐
- What is ARP (address resolution protocol)? (Powercert animated videos)
- Docker Alpine image installation PHP extension redis
- Nine built-in objects of JSP and four scopes of Servlet
- Pytest assert encapsulation
- Idea implements hot deployment
- Yolov4 improved version comes out! Yolov4 extended edition! Yolov4 launched scaled-yolov4: scaling cross stage partial network
- Yolov4 reading notes (with mind map)! YOLOv4: Optimal Speed and Accuracy of Object Detection
- How testers write functional test cases
- PHP compressed file
- couldn‘t be accessed by user ‘_ apt‘
猜你喜欢

Write a "standard" macro min, which inputs two parameters and returns the smaller one

How testers write functional test cases
![[summary] 2021unctf Campus (cry & MISC)](/img/b1/8c4fb9c6d4f1b89361c0487762cdbd.jpg)
[summary] 2021unctf Campus (cry & MISC)

How to solve the problem of flash write protection in STM32?

What is a server? (Powercert animated videos)

Bank digital transformation layout in the beginning of the year, 6 challenges faced by financial level structure and Countermeasures

MySQL is slow to add indexes_ Why is your SQL so slow? Why is your MySQL index invalid?

Sqlmap for interface security testing
![[nail scenario capability package] hospital visitor verification](/img/0e/43433ca5586c48d01708e5fa39a808.jpg)
[nail scenario capability package] hospital visitor verification

Writing manuals using markdown
随机推荐
Docker failed to remotely access 3306 after installing MySQL
On merging and sorting
couldn‘t be accessed by user ‘_ apt‘
Canoe learning notes (2)
Send a more awesome website, which can convert curl commands into code in any language
Solve the parameter problem that laravels cannot receive wechat callback
Common singleton functions traverse dictionary functions
[nailing scenario capability package] video conference (official conference system)
Jmeter- (IV) regular expression for interface testing
Is it legal to open an account for flush stock trading software? Is it safe?
Desktop network error display red ×, Component failed to start
Get the root directory of the package at compile time from buildreoot
On ACM competition
启牛证券开户安全嘛?
[nailing - scenario capability package] nailer card
01 network basics
Writing manuals using markdown
VFS appears when mounting a file system from an SD card: cannot open root device "mmcblk1p2“
lombok
04 disk space management