recursion in 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:
- change brightness of image in java
- set password visible in android
- how to create a java jframe
- alfred workflow
- java shortest if else statement
- java random number
- bukkit java set leather armor color from hex
- java remove duplicates
- system.arraycopy java
- capcitor FERR_CLEARTEXT_NOT_PERMITTED
- javafx fill tableview with data
- write file java
- what it means when create final variable in java
- java program to display characters from a to z using loop
- android studio remove notification bar
- java android edit text set value
- java print treemap
- java initialize int array
- convert two bytes to int java
- java function without return
- how to compare two maps in java
- java create file
- count occurrences of character in string java 8
- arraylist remove method java