java - Trouble figuring out how to return this recursive function? -
new java programming language , confused how run code! using eclipse.
public static string random(string n) { int f = n.length(); if(f <= 1) return n; string b = n.substring(0, f/2); string c = n.substring(f/2, f); return random(c) + random(b); }
i new running java programs in terminal window , can't seem figure out how return value.
put class this
public class myrandom { public static void main(string[] args) { system.out.println(random("abc")); } public static string random(string n) { int length = n.length(); if (length <= 1) return n; string b = n.substring(0, length / 2); string c = n.substring(length / 2, length); return random(c) + random(b); } }
and right click on file , choose "run as"
Comments
Post a Comment