Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

close scanner java

Scanner scanner = new Scanner("Hello world");

//do something with scanner

scanner.close();
Comment

close scanner java

// avoids resource leak
scanner.close();
Comment

how to close scanner in java

import java.util.Scanner;

Scanner scan = new Scanner(system.in);
// ask and pick up responses

scan.close();//helps to avoid memory leaks 
Comment

close scanner java



public class Que01 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int principle=acceptInt(sc,"Principle");
        int roi=acceptInt(sc,"Rate Of Interest");
        int years=acceptInt(sc,"Years");
        sc.close();
        float si=simpleInterest(principle,roi,years);

        System.out.println("Simple Interest for given details is : "+si);
    }

    static int acceptInt(Scanner sc,String s1)
    {   System.out.println("Please Enter value for "+s1+" :");

        int i= sc.nextInt();
        return i;
    }
    static float simpleInterest(int p,int r, int yr)
    {
        return p*yr*r/100;
    }

}```

Comment

PREVIOUS NEXT
Code Example
Java :: a java exception is an instance of ? 
Java :: PlatformException (PlatformException(error, Neither user 10024 nor current process has android.permission.WAKE_LOCK., null, java.lang.SecurityException: Neither user 10024 nor current process has android.permission.WAKE_LOCK. 
Java :: primefaces custom validate 
Java :: add value with n variable with Arraylist in java 
Java :: how to set 2 decimal places in java 
Java :: java check if directory exists 
Java :: android studio start activity 
Java :: string starts with alphabet java 
Java :: convert date to calendar java 
Java :: jackson create object node from string 
Java :: java shorthand if 
Java :: java instant to localdatetime 
Java :: how to delete files in java 
Java :: java check if divisible 
Java :: java days between 
Java :: Java How to use SortedMap? 
Java :: java get cunnect date time 
Java :: why to use serializable with java bean 
Java :: how to count lines from txt java 
Java :: array string remove element java 
Java :: printing in java 
Java :: java import joptionpane 
Java :: java boolean 2d array 
Java :: java get input 
Java :: update query jpa 
Java :: java 8 functional interfaces 
Java :: data java 
Java :: get current unix timestamp java 
Java :: full screen dialog android 
Java :: sorting the characters of a string in java 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =