Java - Recursion with String returning with 0 -
i want homecoming string "electric" number user inputs. have created program. problem it's returning 0 rather showing output only. know problem is, don't know right solution.
example :
input : 3
output :
electric electric electric 0 <- should not have 0 here.
import java.io.*; public class quitx{ public static bufferedreader v = new bufferedreader(new inputstreamreader(system.in)); public static int s; public static void main(string[] args) throws exception{ system.out.println("enter integer : "); s = integer.parseint(v.readline()); system.out.println(x(s)); } public static int x(int s){ if(s <= 0) homecoming s; else{ system.out.println("electric!"); homecoming x (s - 1); } } }
the x()
method returns int
. don't want int
printed. yet you're calling
system.out.println(x(s));
if don't want result printed, then... don't print it:
x(s);
java
No comments:
Post a Comment