#How to recieve System.in from standar io

1 messages · Page 1 of 1 (latest)

small oak
#

So I wanna read input from standard input and I'm using Scanner.

private static String readInput(Scanner input) throws java.io.IOException {
        String line = null;
        try {
            while (input.hasNextLine()) {
                 line = input.nextLine();
            }
            input.close();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println(line);
        return line;
    }```
But this is not exactly achiving my goal. I wanna read few/multiple lines of sentences. Then I wanna work with this but this only reads line by line so that is the problem. Obviously I will implement a stringbuilder but the problem I am having rn is I don't how or when to terminate. If I was reading a file then I will read until there are no more lines but what do I do here?
rugged tinselBOT
#

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

frosty relic
#

ur approach looks flawed for a few reasons. could u step back and explain what u want to achieve in detail please?

#

then we can tell u how to do it in a better way 👍

small oak
frosty relic
#

and how are u planning the user to indicate the end?

#

by closing the input (permanently - ctrl+c)?

small oak
small oak
frosty relic
#

is this an assignment?

small oak
frosty relic
#

could u share the full assignment description please

small oak
frosty relic
#

i need to know more about it though

#

for example if there will be other input as well after or before that, or if it will be used with console pipping or not and more

#

easiest would be to see the full assignment

small oak
#

I'm making a parser for a language and I am reading a text file which I will make syntax tree for

frosty relic
#

there are many ways to approach it and i cant tell u the appropriate if ur holding back the stuff im asking u to share

small oak
#

This is literally the only thing about input in my assigment. It is so unimportant for this assignment that our prof said we could use online code as long as we give credit in the report.

frosty relic
#

it will take much longer for me to pull the stuff out of ur nose than u just sharing the file. or is there any reason u dont just drag drop it?

rugged tinselBOT
frosty relic
#

this cant be the full thing, can it? its missing what u shared previously about System.in

#

anyways, this back and forth took too long for me. im out of time, cheers

small oak
#

but let me double check

small oak
#

You may assume that if the given program is syntactically correct, all numbers that are unlimited in the language definition (distance parameters and repetition parameters) will be at most M, and the total number of instructions executed when the program runs will be at most N (these are guarantees on the input, nothing you need to check).

The input file is at most M MB in size.

Output
If the given Leona program is syntactically incorrect, the following message should be printed, where X is the line on which the (first) syntax error occurs:

Syntax error on line X
See clarifications in the example cases below for which line is considered to be the line of the first syntax error.

Otherwise, if the given program is syntactically correct, a list of line segments drawn by the program should be output. The segments should be output in the same order as they are drawn by Leona, and each segment should be output on a new line, in the following format:

Here is COLOR the color of the line segment (in hex format just like in the language), START is the starting point of the line segment (the point where Leona started when the segment was drawn), and END is the ending point of the line segment (the point where Leona stopped). The coordinates should be accurate up to an error of EPS (if double variables are used and printed with 4 or more decimal places, this should not cause any issues).```
rugged tinselBOT
small oak
#

@frosty relic here is the remaining part

violet dagger
#

@small oak the problem is that we don't know when we should stop reading from system.in

small oak
violet dagger
#

You have to know when it will stop

frosty relic
#

it depends. for example u can use EOF when the input is supposed to be piped

#

java Foo < input.txt

violet dagger
#

Or read a specific word, etc

#

But in any case, there is no generic solution

frosty relic
#

or when the user is supposed to close the connection by using ctrl+c

#

it depends on what the assignment envisions for the interaction

#

and how its automated tests work