#Why am I not getting a space on my print statement?
1 messages · Page 1 of 1 (latest)
<@&987246883653156906> please have a look, thanks.
it would print it. are u sure u even enter it? let it print sth visible
if it doesnt show, ur not entering it to begin with
Im entering it
try "\ "
There is something weird going on
System.out.print(" ");
is this vsc?
Yes
There’s a box with a copy of my code and some format changes above
this is probably an issue with ur terminal and ide then. and not with the code
Oh hea im using bash
ok so bash,
some suck up leading spaces
What do I do?
I press the “run main” below the public static final int
compile it
How
javac YourFileName.java
java YourFileName
for single file
do you use maven or gradle?
or is that not a thing for courses?
could u send ur code file?
yes
then we could try running it on our end
Ok
generally id suggest trying a different console
One sec
or using an IDE like intellij instead (which is used by 70% of all java devs. unlike vsc which is 5%)
or just use a live online java
vsc plus java unfortunately constantly runs into weird issues like this. all the entire time
Okay, and I can use those with Chromebook?
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
Ok, so I just need to download godbolt and then I code on there from now on?
Oh okok thank you lol, I feel like one of those old ppl that started using a phone for the first time
Wait how do I put in the file on to godbolt?
ctrl + c, ctrl + v
Oh lol ok
btw use PrintStream public static void top(PrintStream out) { String poe = "/\\"; for (int i = 1; i<= size; i++) { for (int j = 1; j <= size * 3; j++) { out.print(" "); } out.println(poe); } out.println("_//\\\\_"); }
top(System.out);
} ```
What does it do?
Can make you reuse the code to write to file
and not to console
then you can check the file to see the result
PrintStream fileOut = new PrintStream("output.txt");
top(fileOut);
fileOut.close();
} ```
What is going on here?
remove public from hello class
just for godbolt
but godbolt do not allow to write file
that was just for your computer
as your console is weird
if your console is breaking the result, print the result to file and it should be good in it.
PrintStream is used
you need to import it
import java.io.PrintStream;
Did you learn exception?
Nope
If it’s a long process we can just leave it and I’ll work on this on a public computer tmrw
PrintStream fileOut = new PrintStream("log.txt");
top(fileOut);
fileOut.close();
} catch(Exception e){
System.err.println(e.getMessage());
}```
Where would I place that
try{
PrintStream fileOut = new PrintStream("log.txt");
top(fileOut);
} catch(Exception e){
System.err.println(e.getMessage());
} finally {
fileOut.close();
}
} ```
exception are just error, you try your code, and you catch exceptions
Ok good to know, how do I run this?
the other way is this public static void main(String[] theArgs) { try (PrintStream fileOut = new PrintStream("log.txt")){ top(fileOut); } catch (Exception e){ System.err.println(e.getMessage()); } }
PrintStream is a ressource that open and close
it can actually autoclose
the second way make it autoclose
to know what is autoclosable
your vastly overestimating how much i know, i have no idea whats closing or opening
it got AutoCloseable
well you open a file, and close it
so this
new PrintStream("log.txt")
is to write to a file
so it open the file
If System.out was in your last course, exception will be next week or so.
i'm 4 weeks in and system.out was like the first thing they taught us
and file in 2-3 week
we just barely stared learning about the scanner input stuff and formatting
so does it work on your chromebook?
btw, just to help you a lot,
do not use i, j, k...
use row
, col
It works but it doesn’t show the code it just shows this
, etc
What’s the difference
I mean in visual studio code
It just help you read it
variable with name that mean something are a world of difference.
Okay, that makes sense
also, for (int i = 1; i<= size; i++) is a bit weird, start at 1 go until max
Max?
just make it for (int i = 0; i < size; i++)
Oh
when you do not care for the value of i
How do I see the output
Then how do I open it
My WiFi’s being super slow rn
What does this mean?
red square
Ok I did but everytime I press run main it goes back
Yea
you did not set checkpoint?
How do I do that
I don’t think I have any
good
No red dots on mine
it fail?
what does problem say
“Constant name does not follow naming conventions: size”
Yea
btw save your file before running it
Which one
I think so, if I want to make edits, do I edit it in godbolt save that and then put it in here?
no need for godbolt
it was just to give you a second way to see the output
but you can get it from the file
log.txt
If you overline, you see each space as dot
Ok thank you, btw is there any way to get rid of the lines in between the spaces
you meean the 4 space line that vsc add?
it is just to help you calculate how much space there are
it is setup in the corner
just ignore it
Well you are good to continue.
Okok sounds good, but I gtg I did not expect this was gonna be this complicated. Thank you tho, I appreciate it
Alright 👍
use the snipping tool instead of taking photos with your phone