Home java Java keyboard input

Java keyboard input

Author

Date

Category

Hello! I solve problems in java via intelijidea. I need to enter two numbers from the keyboard, can I somehow enter them myself to check the output? The fact is that when solving the problem, the output is not shown, since no data entered from the keyboard, only the compilation result. Thank you.

public class Solution
{
  public static void main (String [] args) throws Exception
{
  BufferedReader reader = new BufferedReader (new InputStreamReader (System.in));
  String numa = reader.readLine ();
  int num1 = Integer.parseInt (numa);
  String numb = reader.readLine ();
  int num2 = Integer.parseInt (numb);
  for (int i = 1; i & lt; = num1; num1 ++)
  {
    for (int j = 1; j & lt; = num2; num2 ++)
    {
      System.out.print (8);
    }
    System.out.println ();
  }
}
}

Answer 1, authority 100%

Intellij IDEA has a console. You can write there and see the output of the program. Here is a sample code with a picture from the IDE:

import java.util.Scanner;
public class test {
  public static void main (String [] args) {
    Scanner in = new Scanner (System.in);
    System.out.println ("Enter some number:");
    int input = in.nextInt ();
    System.out.println ("Your input is:" + input);
  }
}


Answer 2, authority 67%

Comment out these two sentences

// String numa = reader.readLine ();
// String numb = reader.readLine ();

and write down the values ​​you want to test instead. For example

String numa = "10";
String numb = "20";

Answer 3, authority 33%

for (int i = 1; i & lt; = num1; num1 ++)
  {
    for (int j = 1; j & lt; = num2; num2 ++)
    {
      System.out.print (8);
    }
    System.out.println ();
  }

you have an error using for, because it turns out an infinite loop, where the numbers num1 and num2 increase

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions