Vamos enumerar rsss…
Mil e uma maneiras de ler um inteiro
12 Respostas
1 -
int n = Integer.parseInt( JOptonPane.showInputDialog( "entre com um número" ) );
2 -
Scanner s = new Scanner( System.in );
int n = s.nextInt();
3 -
int n = Integer.parseInt( request.getParameter( "numero" ) );
4 - (JSF)
UIInput input = new UIInput();
...
int n = Integer.parseInt( ( String ) input.getValue() );
5 - (JDBC)
PreparedStatement stmt = conecao.prepareStatement(
"SELECT * FROM tabela " );
ResultSet rs = stmt.executeQuery();
int n = 0;
while ( rs.next() ) {
n = rs.getInt( "coluna" );
}
6 -
Integer on = Integer.valueOf( JOptionPane.showInputDialog( “Entre com o número…” ) );
int n = on.intValue();
7 - Idem ao 6, mas usando Scanner
8 - Idem ao 6, mas usando request.getParameter
9 - Idem ao 6, mas usando JSF
10 - Idem ao 6, mas usando JDBC
public static void main(String[] args) {
int i = Integer.parseInt(args[0]);
}
T+
Virou Orkut? :mrgreen:
Pô, é ler um inteiro do console po rsss…
Via ter alguma utilidade?
int i = new Integer(JOptionPane.showInputDialog("N°")).intValue;
Faltou especificar né

Via ter alguma utilidade?
int i = new Integer(JOptionPane.showInputDialog("N°")).intValue;
Qualquer bobão depois de fazer um hello world e pedirem para ele ler um inteiro do teclado tentaria algo intuitivo como int n = System.in.readInt()… ou algo assim…
Tem a classe System, tem a Scanner, tem a Console, os streams, eu acho que é um exemplo de como Java é confuso às vezes sem precisar…
BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));
int x = Integer.parseInt(reader.readLine());
Grande Raff… essa é clássica…
acho que vou vomitar :mrgreen:
File a =new File("meuArquivoEscritoUmaInt");
Scanner sc = new Scanner(a);
int a = sc.nextInt();