Advertisement
dantepw

Untitled

Feb 23rd, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import javax.swing.JOptionPane;
  5.  
  6. public class Eq1grau {
  7.  
  8. static List <Integer> numeros;
  9.  
  10. public static void main (String[] args){
  11.  
  12. int i;
  13. int j = 0;
  14.  
  15. String s;
  16. s = JOptionPane.showInputDialog(null, "digite: ", "2x + 4y = 18"); //recebe equação do usuário
  17.  
  18. int limite = s.length() -1;
  19. numeros = new ArrayList<>();
  20.  
  21. for(i=0; i < limite; i++){
  22.  
  23. try{
  24.  
  25. boolean x = Character.isDigit(s.charAt(i));
  26.  
  27. while(Character.isDigit(s.charAt(i + j))){
  28. int l = Integer.parseInt(String.valueOf(s.charAt(i+j)));
  29. System.out.print(l);
  30. s += " ";
  31. j += 1;
  32.  
  33. }
  34.  
  35. if(s.charAt(i) == '='){
  36. System.out.print("Encontrei um =");
  37. }
  38.  
  39. System.out.println("");
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /* if(Character.isDigit(s.charAt(i)) && Character.isDigit(s.charAt(i+1))){ //verifica se possui outro número na frente
  47. int l = Integer.parseInt(String.valueOf(s.charAt(i))); //converte esse caractere [número] para int,
  48. int l2 = Integer.parseInt(String.valueOf(s.charAt(i+1))); //se sim, converte esse caractere [número] para int
  49.  
  50. System.out.println("Número de 2 dígitos convertido: "+ l + l2); //imprime na tela
  51. }*/
  52.  
  53.  
  54.  
  55. }
  56.  
  57. catch(StringIndexOutOfBoundsException e){
  58.  
  59. System.out.print("Erro, ");
  60.  
  61. }
  62.  
  63.  
  64. } //final do for
  65. } //fim Main
  66.  
  67. public static void AdicionaNumeroVetor(int AdicionarNumero){
  68. numeros.add(AdicionarNumero);
  69. }
  70. } //fim classe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement