Results 1 to 8 of 8
- 02-18-2013, 04:04 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Can't get this simple Calculator app to work!
I'm writing a java application and don't know why my code isn't working. I'm getting an error because the scanner sc is not closed. I don't know if that's my only error or how to fix it and have looked through google and my book. Here's my code if anyone can take a look at it. I need this program working before midnight!
Help!
Code: Divisor Calculator - Pastebin.com
-
Re: Can't get this simple Calculator app to work!
Hello postauma and welcome to the java-forums.org!
If you have a question about your code, please post that code here in the forum so all can easily see it and evaluate it. Don't forget to use code tags around your posted code too so that it retains its formatting. The link in my signature below will show you how to do this. Good luck, and again welcome!
- 02-18-2013, 04:21 AM #3
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Re: Can't get this simple Calculator app to work!
Thanks for the warm welcome Fuba, and thanks for the advice. Here's my code. I really hope someone can help. I'm starting to feel like this guy ->

Java Code:import java.util.Scanner; public class DivisorCalc { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase ("y")){ System.out.print("Please enter the first number: "); int x = sc.nextInt(); System.out.println("Please enter the second number: "); int y = sc.nextInt(); do{ do{ int tempY = (y-x); y = tempY; } while (y>x); int tempX = x; x = y; y = tempX; } while (x != 0); String message = "Greatest common divisor: " + y + "\n" + ""; System.out.println(message); System.out.println("Continue? (y/n): "); choice = sc.next(); System.out.println(); } } }
-
Re: Can't get this simple Calculator app to work!
Thanks for posting the code. Now are you seeing a compiler error message or a warning? Can you post this message in its entirety and also let us know which line of your code it refers to?
- 02-18-2013, 04:36 AM #5
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Re: Can't get this simple Calculator app to work!
I'm getting this warning at line 10:
Multiple markers at this line
-Line breakpoint:DivisorCalc [line:10] - main(String[])
-Resource leak: 'sc' is never closed
I don't see why that's preventing me from running the program how it is though. :(
- 02-18-2013, 05:02 AM #6
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Re: Can't get this simple Calculator app to work!
Description Resource Path Location Type
Resource leak: 'sc' is never closed DivisorCalc.java /DivisorCalculator/src line 10 Java Problem
- 02-18-2013, 05:39 AM #7
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Re: Can't get this simple Calculator app to work!
My problem is a resource leak. sc is never closed.
- 02-18-2013, 08:50 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: Can't get this simple Calculator app to work!
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Why doesn't my javascript calculator work?
By twinbird24 in forum New To JavaReplies: 2Last Post: 03-29-2012, 05:55 AM -
Can't get java calculator to work
By name in forum New To JavaReplies: 4Last Post: 12-02-2011, 03:38 PM -
actions dont work properly, calculator
By lordjb in forum New To JavaReplies: 14Last Post: 02-03-2011, 07:00 AM -
Simple Calculator
By marksey07 in forum New To JavaReplies: 12Last Post: 01-09-2011, 06:30 AM -
Getting Backspace on a java calculator program to work
By marylanddem in forum New To JavaReplies: 1Last Post: 12-09-2010, 01:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks