# Resource leak: 'in' is never closed..?

• October 3rd, 2012, 12:36 PM
missm
Resource leak: 'in' is never closed..?
Hello everyone! I need help with two things:
1. I get this warning "Resource leak: 'in' is never closed". Why?
2. After every convert is done I want the following message to be printed(example): "1500 miles equals to 2414.02 kilometers". How do I do that?
Thank you
Code :

```import java.util.Scanner;   public class Convert {   public static void main(String[] args) {   Scanner in = new Scanner (System.in);   float miles; float feet; float galons; float km1, km2; float meters1, meters2; float liters1, liters2;   System.out.println("Miles:"); miles = in.nextFloat(); km1 = (float) (miles * 1.609344); km2 = (float) (Math.round(km1*100.0)/100.0); System.out.println("Kilometers ="+km2);   System.out.println("Feet:"); feet = in.nextFloat(); meters1 = (float) (feet * 0.3048); meters2 = (float) (Math.round(meters1*100.0)/100.0); System.out.println("Meters = "+meters2);   System.out.println("Galons:"); galons = in.nextFloat(); liters1 = (float) (galons * 3.78541178); liters2 = (float) (Math.round(liters1*100.0)/100.0); System.out.println("Liters "+liters2); } }```
• October 3rd, 2012, 12:40 PM
curmudgeon
Re: Resource leak: 'in' is never closed..?
Quote:

Originally Posted by missm
Hello everyone! I need help with two things:
1. I get this warning "Resource leak: 'in' is never closed". Why?

You're using a Scanner object but not closing. At the bottom of your program, close the Scanner via in.close();

Quote:

2. After every convert is done I want the following message to be printed(example): "1500 miles equals to 2414.02 kilometers". How do I do that?
You can use variables with your System.out.println statements -- shoot, you're already doing that. So what have you tried and what isn't working with your attempt to do this?
• October 3rd, 2012, 12:47 PM
missm
Re: Resource leak: 'in' is never closed..?
I can't really say I have been trying something except for reading tutorials and the book I have (im referring to number 2. Today I had my first class in Java and this is homework, as you can understand).
However thank you. I did something now and it works. Thank you again!
• October 3rd, 2012, 02:01 PM
curmudgeon
Re: Resource leak: 'in' is never closed..?
You're welcome!