I need to open up the console and type in inputs for my an assignment using Intellij.
Eclipse has a way of doing this using the Scanner
class and reading System.in
but running the same code in IntelliJ does not work as I can't type anything into the console.
Is there any way to do this?
My code is as follows:
public class BasicAssertions {
@Test
public void testAssertions(){
System.out.println("Enter: ");
Scanner reader = new Scanner(System.in);
int first = reader.nextInt();
int second = reader.nextInt();
String s = reader.next();
String s2 = reader.next();
assertTrue(first<=second);
assertFalse(first+second >100);
assertNotEquals(s,s2);
assertNotNull(s2);
}
}
Create a query consoleClick a data source and select File | New | Query Console. Right-click a data source and select New | Query Console. Click a data source, press Alt+Insert , and select Query Console. Click a data source, press Ctrl+Shift+F10 , and select New Query Console.
In the run/debug configuration that will be used for launching the app, click the Logs tab. The Edit Log Files Aliases table displays the list of log files. Select Save console output to file Specify the path to the file.
Navigate to Editor > General > Console. Check the Override console cycle buffer size (1024 KB) option, if it's not already checked. Increase the default value of 1024 KB to your desired size. You could set it to 4096 KB, for example, which is four times the default size.
Configure platform properties:From the main menu, select Help | Edit Custom Properties. If you do not have any project open, on the Welcome screen, click Configure and then select Edit Custom Properties. If you cannot start IntelliJ IDEA, manually create an empty idea.
Just click on the console window and type, it works for me on IntelliJ 13 CE. See the image below, I clicked in the console and wrote the text (it appears in green then, I typed enter and it shows up):
Resolved. A public static void main()
method is required for the correct console to appear, otherwise running using the default JUnit Test configuration will only result in a console that doesn't receive inputs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With