recursion in java
Java
public void removeDigits(String string) {
if(string.length == 1) {
if(Character.isDigit(string.CharAt(0))) {
return "";
} else {
return string;
}
} else {
if(Character.isDigit(string.CharAt(0))) {
return removeDigits(string.substring(1));
} else {
return string.substring(0, 1) + removeDigits(string.substring(1));
public static void main(String[] args) {
String string = "1a2b3c"
System.out.println(removeDigits(string)); //will print "abc"
}// prints x number of $
public static void recursion(int x) {
if(x == 0) { // base case
System.out.println();
} else { // recursive case
System.out.print("$");
recursion(x - 1);
}
}class scratch{
public static long factorial(int n){
if ( n == 1 ){
return 1;
}
else{
return n * factorial( n - 1 );
}
}
public static void main(String[] args) {
System.out.println( factorial(5) );
//Print 120 (5!) to the console
}
}
Also in Java:
- Title
- convert hashset to array
- Category
- Java
- Title
- java how to initialize an array
- Category
- Java
- Title
- exception handling and reprompting
- Category
- Java
- Title
- butterfly pattern program in java
- Category
- Java
- Title
- java thread
- Category
- Java
- Title
- how to check if the file has remaining without reading from it java
- Category
- Java
- Title
- java stack pop
- Category
- Java
- Title
- java random boolean
- Category
- Java
- Title
- how to replace in java
- Category
- Java
- Title
- initialize applet in java
- Category
- Java
- Title
- how to remove all whitespace from string java
- Category
- Java
- Title
- java making a screen
- Category
- Java
- Title
- java nested loop
- Category
- Java
- Title
- java file class
- Category
- Java
- Title
- java replace all html tags
- Category
- Java
- Title
- sc.nextline skips
- Category
- Java
- Title
- esponente in java
- Category
- Java
- Title
- java hahmap
- Category
- Java
- Title
- java enum
- Category
- Java
- Title
- if en une seul ligne java
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- get random number from enum in java
- Category
- Java
- Title
- javafx detect collision
- Category
- Java
- Title
- jtable font size
- Category
- Java
- Title
- java string reverse
- Category
- Java
- Title
- array rotation program in java
- Category
- Java
- Title
- java merge sort
- Category
- Java
- Title
- find duplicate elements in array in java
- Category
- Java
- Title
- java hashmap put
- Category
- Java
- Title
- generic method lambda java
- Category
- Java
- Title
- java set example
- Category
- Java
- Title
- Write a method that raises a number to a power without using Math.pow() method
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- create instance object java
- Category
- Java
- Title
- java go troght loop object
- Category
- Java
- Title
- string to arraylist convert java
- Category
- Java
- Title
- java repository sql find not in list
- Category
- Java
- Title
- initiralizing an arraylist java
- Category
- Java
- Title
- how to create a linked list in java
- Category
- Java
- Title
- android java shared preferences remove key
- Category
- Java
- Title
- on click android studio not working
- Category
- Java
- Title
- spigot actionbar
- Category
- Java
- Title
- java hashmap get value
- Category
- Java
- Title
- java djikstra's algorithm
- Category
- Java
- Title
- java how to show an array
- Category
- Java
- Title
- java array to arraylist
- Category
- Java
- Title
- java vector push_back
- Category
- Java
- Title
- java exceptions for catch
- Category
- Java
- Title
- java swing change label icon
- Category
- Java
- Title
- read csv java android
- Category
- Java
- Title
- creating array java
- Category
- Java
- Title
- Matlab java.lang.IllegalArgumentException: Invalid range
- Category
- Java
- Title
- java string to double
- Category
- Java
- Title
- java get excectuon time
- Category
- Java
- Title
- java download file from url to string
- Category
- Java
- Title
- load contents of file into string java
- Category
- Java
- Title
- how to add strings in java
- Category
- Java
- Title
- how lock horizontal orientation android
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- java override equals and hashcode
- Category
- Java
- Title
- substring java
- Category
- Java
- Title
- how to iterate hashset in java 8
- Category
- Java
- Title
- how to substring in java
- Category
- Java
- Title
- compareto method java
- Category
- Java
- Title
- java 8 find in list by property
- Category
- Java
- Title
- java get keys from hashmap
- Category
- Java
- Title
- java pass array as method parameter
- Category
- Java
- Title
- processing sound library
- Category
- Java
- Title
- writing to a text file java
- Category
- Java
- Title
- java stream collect to string
- Category
- Java
- Title
- java comments
- Category
- Java
- Title
- Gson write json to file
- Category
- Java
- Title
- java loop through object
- Category
- Java
- Title
- 2 decimal places print format JAVA
- Category
- Java
- Title
- how to add to a file in java
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- how to make a variable unchangeable in java
- Category
- Java
- Title
- count occurrences of character in string java 8
- Category
- Java
- Title
- boolean checkbox swing
- Category
- Java
- Title
- how to create a list in java
- Category
- Java
- Title
- math max java
- Category
- Java
- Title
- enum in java
- Category
- Java
- Title
- iterate through hashmap java
- Category
- Java
- Title
- remove last character from string java
- Category
- Java
- Title
- insertion sort doubly linked list java
- Category
- Java
- Title
- how to use spring in java
- Category
- Java
- Title
- processing audio android
- Category
- Java
- Title
- java convert a set to array
- Category
- Java
- Title
- how to add objects in array java
- Category
- Java
- Title
- java mysql springboot jpa stackoverflow
- Category
- Java
- Title
- recursion in java
- Category
- Java
- Title
- Java If statemtn
- Category
- Java
- Title
- iterate map in java 8 using stream
- Category
- Java
- Title
- how to push an element in hashset java
- Category
- Java
- Title
- alfred workflow
- Category
- Java
- Title
- read int from keyboard java
- Category
- Java
- Title
- how to create gravity in java
- Category
- Java
- Title
- java quit application
- Category
- Java
- Title
- java methods
- Category
- Java
- Title
- java stack peek
- Category
- Java