[Java] Try to solve the Fizz Buzz problem using recursive processing

Introduction

Code created

FizzBuzz2.java


/**
 *A method that utilizes recursive processing.
 * @param end The number to end FizzBuzz.
 */
public static void useRecursion(int end) {
	if (end > 1) {
		useRecursion(end - 1);
	}

	if (end%3==0 && end%5==0) {
		System.out.println("Fizz Buzz");
	} else if (end%3==0) {
		System.out.println("Fizz");
	} else if (end%5==0) {
		System.out.println("Buzz");
	} else {
		System.out.println(end);
	}
}

Execution result (* When 20 is specified for the argument end)


1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
Fizz Buzz
16
17
Fizz
19
Buzz

Summary

Recommended Posts

[Java] Try to solve the Fizz Buzz problem using recursive processing
[Java] Try to solve the Fizz Buzz problem
Try to solve a restricted FizzBuzz problem in Java
[Java] Try to implement using generics
Deleting files using recursive processing [Java]
How to solve the unknown error when using slf4j in Java
Interface Try to make Java problem TypeScript 7-3
Try to solve Project Euler in Java
Try using the Stream API in Java
[Processing × Java] How to use the loop
[Processing × Java] How to use the class
[Processing × Java] How to use the function
Try using the Wii remote with Java
Increment behavior Try to make Java problem TypeScript 3-4
String operation Try to make Java problem TypeScript 9-3
Try accessing the dataset from Java using JZOS
How to solve an Expression Problem in Java
Try using the COTOHA API parsing in Java
Try adding text to an image in Scala using the Java standard library
How to solve the font specification problem dedicated to using IntelliJ IDEA (Win x64)
[Java] I tried to solve Paiza's B rank problem
Try implementing the Eratosthenes sieve using the Java standard library
Initialization of for Try to make Java problem TypeScript 5-4
Try global hooking in Java using the JNativeHook library
Try to build a Java development environment using Docker
Command to try using Docker for the time being
You can solve the problem by referring to the two articles !!!
[Java] Try editing the elements of the Json string using the library
Try changing to asynchronous processing via MQ without changing the code
Try Spark Submit to EMR using AWS SDK for Java
The story of pushing Java to Heroku using the BitBucket pipeline
How to play MIDI files using the Java Sound API
Try using RocksDB in Java
Try scraping using java [Notes]
Let's solve the FizzBuzz problem!
[Processing] Try using GT Force.
Input to the Java console
I tried to solve the problem of "multi-stage selection" with Ruby
Try passing values from Java Servlet to iPhone app using JSON
I tried to solve the paiza campaign problem "Challenge from Kaito 813"
I tried to display the calendar on the Eclipse console using Java.
I tried to solve the problem of Google Tech Dev Guide
[java8] To understand the Stream API
Delegate some Java processing to JavaScript
Java comparison using the compareTo () method
Try using Redis with Java (jar)
[Processing × Java] How to use variables
Welcome to the Java Library Swamp! !!
Try to extract java public method
Try using the messaging system Pulsar
Try to implement Yubaba in Java
Try using IBM Java method tracing
The road from JavaScript to Java
[Processing × Java] How to use arrays
Try using Hyperledger Iroha's Java SDK
[Java] Where did you try using java?
How to solve the problem that notification cannot be requested on iOS14
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
[Java] How to get to the front of a specific string using the String class
Iterative processing of Ruby using each method (find the sum from 1 to 10)
About the phenomenon that StackOverflowError occurs in processing using Java regular expressions