irantxu
Posts: 1
Joined: Fri May 10, 2019 2:30 pm

Execute Java code with inputs

Fri May 10, 2019 2:40 pm

Good afternoon,
I was trying to execute an easy Java program (SalsaHoy.java) which requires an input in my Raspberry PI 3 b+, and I was wondering what is the command I should write in order to introduce the input.
The java program is the following one:

public class SalsaHoy(String dia){
if (dia == "Weekend") {
System.out.println("Hay Salsa! :)");
}
else {
System.out.println("No hay Salsa! :(");
}
}


And the commands I have executed in the Raspberry Pi terminal window are the following ones, but I don't know how to introduce the input properly, I receive an error:

cd Java
javac SalsaHoy.java (Weekend)
java SalsaHoy (Weekend)


Thank you in advance for your help

knute
Posts: 474
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Execute Java code with inputs

Fri May 10, 2019 9:44 pm

Take a look at the java.io.Console class.

Return to “General discussion”