Results 1 to 9 of 9
Thread: Why wont this compile?
- 11-17-2010, 05:15 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
Why wont this compile?
i am doing an assignment for a course where you are supposed to create a program where it takes an inputted number of an inputted base, and converts it into a decimal(base 10). i have gotten this far and i am stuck. it will not compile and i am wondering if this is the best way to go about it?
Here is the code i have so far:
Here is the Error message:Java Code:import java.util.Scanner; public class AA3Q1{ public static void main(String[] args) { int base; int binaryNumber; getNumberInBase(); Scanner kbd = new Scanner(System.in); System.out.print("Enter a base."); base = kbd.nextInt(); System.out.print(base, binaryNumber); } public static int getNumberInBase( Scanner scanner, int binaryNumber) { // get input from the user. Scanner kbd = new Scanner(System.in); System.out.print("Enter a binary number:"); binaryNumber = kbd.nextInt(); return binaryNumber; } public static int convertToDecimal(int number, int base, int binaryNumber, int copyOfBinNum, int currPower, int decimalNumber) { // keep looping until -1 is encountered. while (binaryNumber != -1) { // reset values to 0, use copyOfBinNum for calculations. decimalNumber = 0; currPower = 0; copyOfBinNum = binaryNumber; } // keep looping until all digits of copyOfBinNum are removed. while (copyOfBinNum > 0) { // get last digit and strip it off copyOfBinNum currDigit = (int) copyOfBinNum % 10; copyOfBinNum /= 10; // add to the running total if the digit is one if (currDigit < 10) { decimalNumber += Math.pow(base,currPower); return decimalNumber; } // increment the power of two for next loop. currPower++; } return null; } public static void printResults(int number, int base, int result) { convertToDecimal(); System.out.println("you input the number " + number + " in the base " + base + ". This number as a power of 10 is " + result + "."); } }
C:\Users\chelsea\Downloads\A3Q1.java:19: cannot find symbol
symbol : variable nextInt
location: class java.util.Scanner
base=keyboard.nextInt;
^
1 error
Tool completed with exit code 1
- 11-17-2010, 05:30 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
That code is not in the code you posted.
Therefore that error has not come from compiling this code.
- 11-17-2010, 06:45 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 21
- Rep Power
- 0
Correct code or not, that error arises when you forget the parenthesis after nextInt. So variable = kbd.nextInt();
Also, the code that you inputted here does call the methods you have created but does not know where to assign the returned value. For example:
then you're not calling the rest of your methods so that code never executes.Java Code:public static void main(String[] args) { int base; int binaryNumber; [COLOR="Red"]binaryNumber = [/COLOR]getNumberInBase(); Scanner kbd = new Scanner(System.in); System.out.print("Enter a base."); base = kbd.nextInt(); System.out.print(base, binaryNumber); }Last edited by Allspark; 11-17-2010 at 06:52 PM.
- Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -
- 11-17-2010, 07:46 PM #4
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
thank-you both of you. but ok so how do i show it where to assign the value? and do i have to call all of the methods in the code for it to execute?
- 11-17-2010, 08:54 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
ok figured something out!!
Ok so i got am little bit further. now there is only 1 error message. Any ideas how i would fix it?
Here is the code:
Here is the error message:Java Code:import java.util.Scanner; public class DanielsonErikA3Q1{ private static int currDigit; private static int base; public static void main(String[] args) { int base; int binaryNumber; Scanner kbd = new Scanner(System.in); System.out.print("Enter a base."); base = kbd.nextInt(); System.out.println(base, binaryNumber); } public static int getNumberInBase( Scanner scanner, int binaryNumber) { // get input from the user. Scanner kbd = new Scanner(System.in); System.out.print("Enter a binary number:"); binaryNumber = kbd.nextInt(); return binaryNumber; } public static int convertToDecimal(int number, int base, int binaryNumber, int copyOfBinNum, int currPower, int decimalNumber) { // keep looping until -1 is encountered. while (binaryNumber != -1) { // reset values to 0, use copyOfBinNum for calculations. decimalNumber = 0; currPower = 0; copyOfBinNum = binaryNumber; } // keep looping until all digits of copyOfBinNum are removed. while (copyOfBinNum > 0) { // get last digit and strip it off copyOfBinNum currDigit = (int) copyOfBinNum % 10; copyOfBinNum /= 10; // add to the running total if the digit is one if (currDigit < 10) { decimalNumber += Math.pow(base,currPower); return decimalNumber; } // increment the power of two for next loop. currPower++; } return decimalNumber; } public static void printResults(int number, int base, int result) { System.out.println("you input the number " + number + " in the base " + base + ". This number as a power of 10 is " + result + "."); } }
C:\Users\chelsea\Downloads\DanielsonErikA3Q1.java: 20: cannot find symbol
symbol : method println(int,int)
location: class java.io.PrintStream
System.out.println(base, binaryNumber);
^
1 error
Tool completed with exit code 1
-
The error message is telling you what's wrong. It can't find println(int, int) because this method simply doesn't exist. println takes a String parameter, not two ints.
- 11-17-2010, 09:34 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 6
- Rep Power
- 0
Oops!
Oops! sorry about that posted the wrong code. thanks though. here is what i am having a problem with.
Here is the code:
Here is the Error:Java Code:import java.util.Scanner; public class DanielsonErikA3Q1{ private static int currDigit; private static int base; private static int binaryNumber; private static int decimalNumber; public static void main(String[] args) { int base; int binaryNumber; Scanner kbd = new Scanner(System.in); System.out.print("Enter a base."); base = kbd.nextInt(); System.out.println(base + "" + binaryNumber); printResults(); } public static int getNumberInBase( Scanner scanner, int binaryNumber) { // get input from the user. Scanner kbd = new Scanner(System.in); System.out.print("Enter a binary number:"); binaryNumber = kbd.nextInt(); return binaryNumber; } public static int convertToDecimal(int number, int base, int binaryNumber, int copyOfBinNum, int currPower, int decimalNumber) { // keep looping until -1 is encountered. while (binaryNumber != -1) { // reset values to 0, use copyOfBinNum for calculations. decimalNumber = 0; currPower = 0; copyOfBinNum = binaryNumber; } // keep looping until all digits of copyOfBinNum are removed. while (copyOfBinNum > 0) { // get last digit and strip it off copyOfBinNum currDigit = (int) copyOfBinNum % 10; copyOfBinNum /= 10; // add to the running total if the digit is one if (currDigit < 10) { decimalNumber += Math.pow(base,currPower); return decimalNumber; } // increment the power of two for next loop. currPower++; } return decimalNumber; } public static void printResults(int binaryNumber, int base, int decimalNumber) { System.out.println("you input the number " + binaryNumber + " in the base " + base + ". This number as a power of 10 is " + decimalNumber + "."); } }
C:\Users\chelsea\Downloads\DanielsonErikA3Q1.java: 23: printResults(int,int,int) in DanielsonErikA3Q1 cannot be applied to ()
printResults();
^
1 error
Tool completed with exit code 1
- 11-17-2010, 10:49 PM #8
Member
- Join Date
- Nov 2010
- Posts
- 12
- Rep Power
- 0
At the end of your main() method, you call printResults, but pass no arguments to it. It requres three int values.
- 11-18-2010, 05:33 AM #9
Similar Threads
-
wont validate
By karq in forum XMLReplies: 1Last Post: 10-07-2010, 05:33 PM -
Triangles wont draw Help?
By The_Sponzy_Paradox in forum Java 2DReplies: 9Last Post: 03-22-2010, 02:42 AM -
Why wont import jm.util.*; work??
By cakepizza in forum New To JavaReplies: 2Last Post: 01-01-2010, 11:19 PM -
why wont it compile
By bje98f in forum Advanced JavaReplies: 1Last Post: 04-23-2009, 10:55 PM -
simple problem - code wont compile
By dirtycash in forum New To JavaReplies: 1Last Post: 11-20-2007, 05:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks