Home java Entering data from Java keyboard

Entering data from Java keyboard




I will immediately write, I’m new to Java, and I know the language very badly. I tried to write a program, but it gives an error. I will be grateful if you write what I made a mistake. Here is the code:

Public Class Main {
  Throws java.io.ioException {
    Char x;
    x = (char) System.in.Read ();
    System.out.printLN (X);

Answer 1, Authority 100%

It is better to use the following syntax:

import java.util. *;
Public Class Main.
  Public Static Void Main (String [] Args) {
  Scanner in = New Scanner (System.in);
  String x = in.nextline ();
  System.Out.print (x);

Answer 2

Use Scanner class:

scanner in = new scanner (System.in);
String s = in.next ();
System.Out.print (S);

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