0

I just started my adventure of programming yesterday and already have a problem I can't solve. I tried to make my program ask me for my age and to return it to me.

I entered 24 and it returned 50. I managed to find out that it uses the Ascii chart or something like that and that it converts only the very first number to a decimal number. So in this case 2->50.

I tried to find a solution online but I only found things about converting numbers to characters.

I am sorry if I missed the obvious and my question is redundant but I really don't have any experience in programming and don't know what else to google.

This is my code:

package de.galileocomputing.schroedinger.java.kapitel01;
import java.io.IOException;

public class HalloSchroedinger {

    public static void main(String[] args) throws IOException {
        System.out.println("Hallo " + args[0]);
        System.out.println("Wie alt bist du?");
        int alter = System.in.read();
        System.out.println(alter);

    }

}
  • 3
    Look up how to use Java's `Scanner` class, then use its `nextInt` method. This is a little broad for here though. – Carcigenicate Jul 25 '18 at 18:10
  • "something like that": Yes, [Unicode](http://www.unicode.org/charts/nameslist/index.html)'s UTF-16 character codes. But `read` reads byte by byte and UTF-16 character codes take two bytes. (The next read would give you 0.) – Tom Blodget Jul 25 '18 at 20:02

0 Answers0