+ 2

Any reason why i cant print a space with my code? Sorry if it looks pointless its really not 😋. Thanks

public class Program {static void print(String x){System.out.print(x);} public static void main(String[] args) { for(int i = 0; i < 5 ;++i){ if(i == 1){for(int a = 0; a < 10;++a){print(" ");}} }

26th Aug 2017, 10:13 PM
D_Stark
D_Stark - avatar
7 Réponses
+ 3
Ya, when running it you should just see a blank screen for output, but if in the code playground you're receiving the "no output" response, then it is just the code playground being wonky.
26th Aug 2017, 11:11 PM
ChaoticDawg
ChaoticDawg - avatar
+ 5
You have some curly brace issues, but once fixed it works: public class Program { static void print(String x) { System.out.print(x); } public static void main(String[] args) { print("|"); // added to see spaces are printed for(int i = 0; i < 5 ; ++i) { if(i == 1) { for(int a = 0; a < 10; ++a) { print(" "); } } } print("|"); // added to see spaces are printed } }
26th Aug 2017, 10:32 PM
ChaoticDawg
ChaoticDawg - avatar
+ 5
Output is a console full of stuff... That's called spaces...😃😃😃
27th Aug 2017, 5:27 AM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 2
The post here looks to be missing the last 2 closing curly braces (main method and Program class). When all you're outputing is spaces and/or newlines you won't see any output, which is why I put in the pipes before and after the for loop.
26th Aug 2017, 10:59 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thanks again chaotic works well, with mine i was getting no output for spaces but output for other values do u know what curley bracket was causing the problem?
26th Aug 2017, 10:53 PM
D_Stark
D_Stark - avatar
+ 1
yeah i agree becuase even with your code if you delete both print("|") so it outputs the spaces only from the loop you get the no output response also. so im guessing you cant loop and print nothing on its own it has to have a character somewere before of after the loop.
26th Aug 2017, 11:22 PM
D_Stark
D_Stark - avatar
0
oh so if theres nothing show theres no output... right i get it, it kind of makes sense really 😅 lol
26th Aug 2017, 11:02 PM
D_Stark
D_Stark - avatar