Java 07 Entrada Dados

8,069 views
7,813 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
8,069
On SlideShare
0
From Embeds
0
Number of Embeds
36
Actions
Shares
0
Downloads
157
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java 07 Entrada Dados

  1. 1. Entrada de Dados <ul><ul><li>Regis Pires Magalhães </li></ul></ul><ul><ul><li>[email_address] </li></ul></ul>
  2. 2. Entrada de Dados <ul><li>Usando a classe BufferedReader </li></ul>import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Teste { public static void main(String[] args) { BufferedReader dataIn = new BufferedReader( new InputStreamReader(System. in )); try { System. out .print( &quot;Digite um nome: &quot; ); String nome = dataIn.readLine(); System. out .println(nome); } catch (IOException e) { System. out .println( &quot;Error in getting input&quot; ); } } }
  3. 3. Entrada de Dados <ul><li>Usando a classe Scanner </li></ul><ul><li>Métodos disponíveis: </li></ul><ul><ul><li>next(), nextInt(), nextByte(), nextLong(), nextFloat(), nextDouble() </li></ul></ul>import java.util.Scanner; public class Teste { public static void main(String[] args) { Scanner sc = new Scanner(System. in ); System. out .print( &quot;Digite um nome: &quot; ); String nome = sc.next(); System. out .println(nome); } }
  4. 4. Entrada de Dados <ul><li>Usando a classe Console </li></ul><ul><li>String nome = System. console ().readLine(); </li></ul><ul><li>Usando a classe JOptionPane </li></ul><ul><li>String nome = JOptionPane. showInputDialog ( &quot;Nome:&quot; ); </li></ul><ul><ul><li>Nota: É necessário fazer o import da classe javax.swing.JOptionPane . </li></ul></ul>
  5. 5. Saída de Dados <ul><li>Usando a classe JOptionPane </li></ul><ul><ul><li>JoptionPane. showMessageDialog ( null , &quot;PosBD4&quot; ); </li></ul></ul><ul><ul><li>Nota: É necessário fazer o import da classe javax.swing.JOptionPane. </li></ul></ul>
  6. 6. JOptionPane - Exemplo import javax.swing.JOptionPane; public class Teste { public static void main(String[] args) { String nome = JOptionPane. showInputDialog ( &quot;Nome:&quot; ); JOptionPane. showMessageDialog ( null ,nome); } }

×