+ 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(" ");}} }
7 odpowiedzi
+ 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.
+ 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
}
}
+ 5
Output is a console full of stuff...
That's called spaces...😃😃😃
+ 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.
+ 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?
+ 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.
0
oh so if theres nothing show theres no output... right i get it, it kind of makes sense really 😅 lol