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 :: what is ioexception in java 
Java :: add random numbers to array 
Java :: java compile 
Java :: easter egg 
Java :: Java Add elements to a HashMap 
Java :: can we override the overloaded method in java 
Java :: how to create a new imageview in android java 
Java :: java create a string 
Java :: intent class for url and phone and others 
Java :: array of string java 
Java :: example of a for loop 
Java :: void * to int 
Java :: Exception handling using try...catch 
Java :: How to remove an element from a Java List? 
Java :: java literals 
Java :: nested class in java 8 
Java :: vim yank to clipboard 
Java :: Service vs IntentService. 
Java :: output of this 
Java :: how to change state of a Switch programmatically andoir dstudio 
Java :: java transformar string a url 
Java :: java cambiar formato de fecha 
Java :: REGEX ___ get length of array in java 
Java :: Remove ArrayList Elements using remove() function 
Java :: java Least prime factor of numbers till n 
Java :: set maven goals in eclipse 
Java :: java main setup 
Java :: .throwFor in java 
Java :: android bootom app bar tab bar 
Java :: android diagonal gradle 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =