se ho capito bene devi vedere cosa stai inserendo...ti do due classi fatte da un mio prof spero ti siano utili
codice:
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Tastiera
{
public static int leggi()
{
InputStreamReader reader = new InputStreamReader (System.in);
BufferedReader myInput = new BufferedReader (reader);
String str= new String();
try {
str = myInput.readLine();
return (Integer.parseInt(str));
}
catch (IOException e)
{
System.out.println ("Si e' verificato un errore: " + e);
System.exit(-1);
}
return 0;
}
public static double leggiDouble()
{
InputStreamReader reader = new InputStreamReader (System.in);
BufferedReader myInput = new BufferedReader (reader);
String str= new String();
try {
str = myInput.readLine();
return (Double.parseDouble(str));
}
catch (IOException e)
{
System.out.println ("Si e' verificato un errore: " + e);
System.exit(-1);
}
return 0;
}
public static double leggiFloat()
{
InputStreamReader reader = new InputStreamReader (System.in);
BufferedReader myInput = new BufferedReader (reader);
String str= new String();
try {
str = myInput.readLine();
return (Float.parseFloat(str));
}
catch (IOException e)
{
System.out.println ("Si e' verificato un errore: " + e);
System.exit(-1);
}
return 0;
}
public static String leggiString()
{
InputStreamReader reader = new InputStreamReader (System.in);
BufferedReader myInput = new BufferedReader (reader);
String str= new String();
try {
str = myInput.readLine();
return str;
}
catch (IOException e)
{
System.out.println ("Si e' verificato un errore: " + e);
System.exit(-1);
}
return "";
}
}
codice:
public class Schermo
{
public static final void scrivi(String s)
{
System.out.println(s);
}
public static final void scrivi(int s)
{
System.out.println(s);
}
public static final void scrivi(char s)
{
System.out.println(s);
}
public static final void scrivi(float s)
{
System.out.println(s);
}
public static final void scrivi(double s)
{
System.out.println(s);
}
public static final void scrivi(boolean s)
{
System.out.println(s);
}
public static final void scrivi(byte s)
{
System.out.println(s);
}
public static final void scrivi(long s)
{
System.out.println(s);
}
}
per utilizzartle fai ad esempio
String n;
n=Tastiera.leggiString();