Προς το περιεχόμενο

eisodos.close();???????? Τι σημαινει στην java?(Το πρόγραμμα που φτιάχνουμε παίρνει αριθμούς από το χρήστη και τυπώνει αν ο αριθμός αυτός είναι περιττός ή άρτιος .)


cur24

Προτεινόμενες αναρτήσεις

package LessonFourExample;

import  java.util,Scanner;

public class LessonFourExample{

      public static void main(String[] args){

      Scanner eisodos=new Scanner(System.in);

     int stopper;

     int imput;

     while(true){

         System.out.println("Dose ton arithmo:");

         imput=eisodos.nextInt();

         if(imput==stopper){

              break;

        }

       if(imput%2==1){

            System.out.println("O arithmos" + imput+ "einai peritos");

       }

      else{

           System.out.println("O arithmos " + imput + "einai artios!");

         }

   }

 System.out.println("Telos programmatos");

 eisodos.close();

  }

}

 

 

 

       

 

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

Κλείνει το Scanner(eisodos) που είναι ένα stream. Γενίκα καλό ειναι να τα κλέινεις τα streams για να απελευθερώθουν τα resources που έχει δεσμεύσει το πρόγραμμα. Συνήθως αν δεν το κάνεις σου πετάει και warning ο compiler.

  • Like 1
Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#close()

Αναφορά σε κείμενο

public void close()
Closes this scanner.

If this scanner has not yet been closed then if its underlying readable also implements the Closeable interface then the readable's close method will be invoked. If this scanner is already closed then invoking this method will have no effect.

Attempting to perform search operations after a scanner has been closed will result in an IllegalStateException.

Specified by:
close in interface Closeable
Specified by:
close in interface AutoCloseable

 

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...