Advertisement
amadeoterri

Untitled

Oct 26th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package oef3_alternatief;
  7.  
  8. import java.net.URL;
  9. import java.util.ResourceBundle;
  10. import javafx.fxml.FXML;
  11. import javafx.fxml.Initializable;
  12. import javafx.scene.control.Button;
  13. import javafx.scene.control.TextArea;
  14. import javafx.scene.control.TextField;
  15. import javafx.scene.input.MouseEvent;
  16.  
  17. /**
  18.  * FXML Controller class
  19.  *
  20.  * @author Amadeo
  21.  */
  22. public class FXML3_extraController implements Initializable {
  23.  
  24.     @FXML
  25.     private TextField txtAantal;
  26.     @FXML
  27.     private Button btnInvoer;
  28.     @FXML
  29.     private TextArea txtResultaat;
  30.  
  31.     /**
  32.      * Initializes the controller class.
  33.      */
  34.     @Override
  35.     public void initialize(URL url, ResourceBundle rb) {
  36.         // TODO
  37.     }    
  38.  
  39.     @FXML
  40.     private void clicked_invoer(MouseEvent event) {
  41.         //opvragen ingegven getallen
  42.         String sGetallen = txtAantal.getText();
  43.         int iGrootste =0;
  44.         //huidig getal uit reeks getallen
  45.         int iGetal;
  46.         int iAantalGetallen=1;
  47.        
  48.         int iKomma =0;
  49.        
  50.         //aantal komma's in sGetallen
  51.         //vb. 1,2,3,4
  52.         for (int i = 0; i < sGetallen.length(); i++) {
  53.             // is huidige positie in sGetallen een komma?
  54.             if(sGetallen.charAt(i) == ',')
  55.             {
  56.                 iAantalGetallen++;
  57.             }  
  58.         }
  59.        
  60.         for (int i = 0; i < iAantalGetallen; i++) {
  61.             //1,2,3,4
  62.             if(sGetallen.contains(","))
  63.             {
  64.                 //positie komma
  65.                 iKomma = sGetallen.indexOf(",");
  66.                 //ikomma = 1
  67.                 iGetal = Integer.parseInt(sGetallen.substring(0,iKomma));
  68.                
  69.                 //overschrijven van sGetallen zodat het gedeelte na de komma nog overblijft
  70.                 //ikomma + 1 want anders wordt sGetallen: ,2,3,4
  71.                 sGetallen = sGetallen.substring(iKomma+1);
  72.             }
  73.             else
  74.             {
  75.             iKomma = 0;
  76.             iGetal = Integer.parseInt(sGetallen);
  77.            
  78.             }
  79.            
  80.             if(iGetal>=iGrootste)
  81.                 {
  82.                     iGrootste = iGetal;
  83.                 }
  84.             }
  85.            
  86.         txtResultaat.setText("Grootste getal: " + String.valueOf(iGrootste));
  87.        
  88.  
  89.     }
  90.    
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement