Article View: es.comp.lenguajes.java
Article #29796Re: No me creereis
From: Chano G�mez
Date: Sun, 26 Oct 1997 00:00
Date: Sun, 26 Oct 1997 00:00
30 lines
1271 bytes
1271 bytes
> No me vais a creer....no puedo leer un entero del teclado.
Prueba con el c�digo que te mando.
Es l�gico que no te funcionara, ya que est�s leyendo el c�digo ASCII del texto
introducido. Tienes que leer el n�mero como una cadena de texto, y luegos usar
Integer.parseInt() para convertir el texto en n�mero.
En mi programa yo no lo hago, pero deber�s controlar las excepciones para los
n�meros introducidos incorrectamente.
Un saludo.
Chano.
===========================
import java.io.*;
class entrada{
public static void main(String args[]) throws Exception{
System.out.print("Introduce un n�mero: ");
DataInputStream dis = new DataInputStream(System.in);
String cadena = dis.readLine();
int n = Integer.parseInt(cadena);
System.out.println("Has escrito el n�mero " + n);
}
}
Technical Details
Message-ID:
<34538900.95DCE68E@ran.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<62q4br$9mj$1@erika.cica.es>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: 1116f3,51542217ac7971ec X-Google-Attributes: gid1116f3,public From: "Chano G�mez" <chano@ran.es> Subject: Re: No me creereis Date: 1997/10/26 Message-ID: <34538900.95DCE68E@ran.es> X-Deja-AN: 285118911 References: <62q4br$9mj$1@erika.cica.es> Organization: Unisource Espana NEWS SERVER Newsgroups: es.comp.lenguajes.java