svush Posted September 7, 2012 Share Posted September 7, 2012 Hey! I've just started playing around with java programming, and i was wondering if someone could help me get this result with only the use of for loops? 0 10 210 3210 43210 543210 6543210 76543210 876543210 9876543210 Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 Why would you need more than one loop? Also, Java != JavaScript != Java. Quote Link to comment Share on other sites More sharing options...
svush Posted September 7, 2012 Author Share Posted September 7, 2012 Ok thanks for pointing out that im a newbeginner and that i put this in the wrong forum. Didnt help me much tho. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 So you are trying to do it in Java then. I can't help because I don't write Java, so I've moved it to the Java forum. I can tell you there is no reason you need more than one loop. Here's the PHP code: <?php for($i=0; $i<=9; $i++){ if(!isset($string)){ $string = "$i"; }else{ $string = $i.$string; } echo $string.'<br>'; } ?> PS: If this is homework, you need to learn to do it yourself. See the rules. Quote Link to comment Share on other sites More sharing options...
svush Posted September 7, 2012 Author Share Posted September 7, 2012 oki thx Quote Link to comment Share on other sites More sharing options...
Maq Posted September 7, 2012 Share Posted September 7, 2012 Java would look something like: String output = ""; for(int i=0; i{ output = i + output; System.out.println(output); } Quote Link to comment Share on other sites More sharing options...
krakjoe Posted September 24, 2012 Share Posted September 24, 2012 (edited) I think maybe the point was to get you to look at how to control the flow of nested loops ... public class Answer { public static void main(String argv[]) { for ( int start = 0; start <= 9; start++ ){ System.out.printf("%d", start); for ( int inner = start-1; inner>=0; inner-- ){ System.out.printf("%d", inner); } System.out.print("\n"); } } } Jessica is right, you should try to do this for yourself, at the very least make sure you understand the answer, look for ways to improve it, perhaps find another way using a different control structure ... Have fun Edited September 24, 2012 by krakjoe Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.