Recursive üs alma programı
import java.util.Scanner; //üsalma recursive public class ornek { public static int us(int taban,int usdeger){ if (usdeger==0) return 1; else if(taban==1) return 1; else return taban*us(taban,usdeger-1); } public static void main(String[] args) { Scanner gir=new Scanner(System.in); System.out.println("taban gir:"); int taban=gir.nextInt(); System.out.println("üsdeğer gir:"); int usdeger=gir.nextInt(); System.out.println("sonuc: "+us(taban, usdeger)); } }
package forexam;
import java.util.Scanner;
public class Forexam {
public static int us_alma(int taban,int us){
int sonuc=1;
if(taban==1 ||us==0)
return 1;
else
return sonuc*taban*us_alma(taban, us-1);
}
public static void main(String[] args){
// Recursive üs alma programı.
Scanner scn =new Scanner(System.in);
System.out.println(“tabanı gir”);
int taban=scn.nextInt();
System.out.println(“usu gir”);
int us=scn.nextInt();
System.out.println(us_alma(taban,us));
}
}