#Why am I not getting a space on my print statement?

1 messages · Page 1 of 1 (latest)

trim hatch
#

I’m trying to print just a space by itself but Java is just ignoring the space. It will work if I put any character in but a space by itself just gets ignored. The code on the bottom is what pops up. I’m trying to make it to where the /\ is in the middle of not on the left.

chilly quartzBOT
#

<@&987246883653156906> please have a look, thanks.

fierce spindle
#

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

gleaming flame
#

There is something weird going on

#

System.out.print(" ");

trim hatch
gleaming flame
#

wait, what console do you use?

#

just bash?

trim hatch
#

How do I check, I’m very new to Java

#

Visual studios maybe?

gleaming flame
#

is this vsc?

trim hatch
#

Yes

gleaming flame
#

what does it say in the right

trim hatch
#

There’s a box with a copy of my code and some format changes above

gleaming flame
fierce spindle
#

this is probably an issue with ur terminal and ide then. and not with the code

trim hatch
#

Oh hea im using bash

gleaming flame
#

ok so bash,

fierce spindle
#

some suck up leading spaces

gleaming flame
#

how do you run it?

#

do you compile, then start the jar?

trim hatch
#

I press the “run main” below the public static final int

gleaming flame
#

compile it

trim hatch
#

How

gleaming flame
#

javac YourFileName.java

#

java YourFileName

#

for single file

#

do you use maven or gradle?

#

or is that not a thing for courses?

trim hatch
#

I would not know

#

I’m on a hp Chromebook if that helps

#

Using Linux files

fierce spindle
#

could u send ur code file?

gleaming flame
#

yes

fierce spindle
#

then we could try running it on our end

trim hatch
#

Ok

fierce spindle
#

generally id suggest trying a different console

trim hatch
#

One sec

fierce spindle
#

or using an IDE like intellij instead (which is used by 70% of all java devs. unlike vsc which is 5%)

gleaming flame
#

or just use a live online java

fierce spindle
#

vsc plus java unfortunately constantly runs into weird issues like this. all the entire time

gleaming flame
trim hatch
#

Okay, and I can use those with Chromebook?

gleaming flame
#

send the file

trim hatch
#

Working on it, I didn’t have disc on my laptop

chilly quartzBOT
# trim hatch ok here

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

gleaming flame
#

add an executor only and you will have the console

#

it work

trim hatch
#

Ok, so I just need to download godbolt and then I code on there from now on?

gleaming flame
#

xD it is a live website

#

to test code and optimise it

trim hatch
#

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?

gleaming flame
#

ctrl + c, ctrl + v

trim hatch
#

Oh lol ok

gleaming flame
#

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);        
    }  ```
trim hatch
#

What does it do?

gleaming flame
#

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(); 
    }   ```
trim hatch
#

What is going on here?

gleaming flame
#

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

trim hatch
#

Yea I was abt ask about that, ty ty

#

What about the cannot find symbol thingy

gleaming flame
#

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;

trim hatch
#

Ok last one I think

#

I imported the print stream btw the error msg is covering it

gleaming flame
#

Did you learn exception?

trim hatch
#

Nope

#

If it’s a long process we can just leave it and I’ll work on this on a public computer tmrw

gleaming flame
#
            PrintStream fileOut = new PrintStream("log.txt");
            top(fileOut);    
            fileOut.close();  
        }  catch(Exception e){
           System.err.println(e.getMessage());
        }```
trim hatch
#

Where would I place that

gleaming flame
#
        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

trim hatch
#

Ok good to know, how do I run this?

gleaming flame
#

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

trim hatch
#

your vastly overestimating how much i know, i have no idea whats closing or opening

gleaming flame
#

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.

trim hatch
#

i'm 4 weeks in and system.out was like the first thing they taught us

gleaming flame
#

and file in 2-3 week

trim hatch
#

we just barely stared learning about the scanner input stuff and formatting

gleaming flame
#

so does it work on your chromebook?

#

btw, just to help you a lot,

#

do not use i, j, k...

#

use row

#

, col

trim hatch
#

It works but it doesn’t show the code it just shows this

gleaming flame
#

, etc

trim hatch
#

What’s the difference

gleaming flame
#

I mean in visual studio code

#

It just help you read it

#

variable with name that mean something are a world of difference.

trim hatch
#

Okay, that makes sense

gleaming flame
#

also, for (int i = 1; i<= size; i++) is a bit weird, start at 1 go until max

trim hatch
#

Max?

gleaming flame
#

just make it for (int i = 0; i < size; i++)

trim hatch
#

Oh

gleaming flame
#

when you do not care for the value of i

trim hatch
#

How do I see the output

gleaming flame
#

open the file

#

godblot does not have file

trim hatch
#

Then how do I open it

gleaming flame
#

in visual studio code

#

just open it.

trim hatch
#

My WiFi’s being super slow rn

gleaming flame
#

or just click your run button

trim hatch
#

What does this mean?

gleaming flame
#

you are in debug mode

#

stop them

#

the 3

trim hatch
#

Ok I did

#

How do I get out of debug mode

gleaming flame
#

red square

trim hatch
#

Ok I did but everytime I press run main it goes back

gleaming flame
#

that run?

trim hatch
#

Yea

gleaming flame
#

you did not set checkpoint?

trim hatch
#

How do I do that

gleaming flame
#

you dont need to have them, if you have any remove them

#

just click it

trim hatch
#

I don’t think I have any

gleaming flame
#

good

trim hatch
#

No red dots on mine

gleaming flame
#

it fail?

trim hatch
gleaming flame
#

what does problem say

trim hatch
#

“Constant name does not follow naming conventions: size”

gleaming flame
#

that just a warning, not a hard fail

#

your java file is in a folder right?

trim hatch
#

Yea

gleaming flame
#

did you open your folder

#

in vsc

#

do you see the log.txt file in it?

trim hatch
#

Oh I think I see

#

Maybe not

#

Should I be opening the log.txt file or the hello file

gleaming flame
trim hatch
gleaming flame
#

btw save your file before running it

trim hatch
#

Which one

gleaming flame
#

Hello.java

#

so it work

#

nice

trim hatch
#

I think so, if I want to make edits, do I edit it in godbolt save that and then put it in here?

gleaming flame
#

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

trim hatch
#

Ohhh ok yea its working

#

I see wym now

gleaming flame
#

If you overline, you see each space as dot

trim hatch
#

Ok thank you, btw is there any way to get rid of the lines in between the spaces

gleaming flame
#

you meean the 4 space line that vsc add?

trim hatch
#

Yea

#

It’s only 3 for me but yea

gleaming flame
#

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.

trim hatch
#

Okok sounds good, but I gtg I did not expect this was gonna be this complicated. Thank you tho, I appreciate it

#

Alright 👍

pulsar glen
# trim hatch

use the snipping tool instead of taking photos with your phone