Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 8th, 2006, 09:19 AM
Registered User
 
Join Date: Feb 2006
Location: Belleville, NJ, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to nappydyno234 Send a message via Yahoo to nappydyno234
Default Programming Problem

I received errors while trying to compile the following code:

public class power {
    public static void main(String[] args) {
     int base;
     int order;
     int p;
     System.in.println(base, order);
     System.out.println("Java power" base order);
     System.out.println("Mariner Eccles");
     p = pow(base, order);
     System.out.println(p);
    }
}

Here are the errors:

power.java:6: cannot find symbol
symbol : method println(int,int)
location: class java.io.InputStream
     System.in.println(base, order);
              ^
power.java:7: cannot find symbol
symbol : method println(java.lang.String,int,int)
location: class java.io.PrintStream
     System.out.println("Java power", base, order);
               ^
power.java:9: cannot find symbol
symbol : method pow(int,int)
location: class power
     p = pow(base, order);
         ^
3 errors

Once again, if anyone knows anything on how to help, please let me know. It would be greatly appreciated.

Reply With Quote
  #2 (permalink)  
Old February 9th, 2006, 05:41 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

these r all accept arguments of string u have to convert them to string..for e.g System.out.println(""+ base + "" + order);

Reply With Quote
  #3 (permalink)  
Old February 11th, 2006, 12:27 PM
Authorized User
 
Join Date: Jan 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to longjava
Default

You have quite a few errors in your code:

Error 1:
At line - System.in.println(base, order);
The System.in is an instance of InputStream class and it has no method name println()

Error 2:
At line - System.out.println("Java power" base order);
You would need to use the + operator to convert the base and order vriables into a string type. For example:
System.out.println( "Java power " + base + " " + order );

Error 3:
At line - p = pow(base, order);
since the pow() function is a static method of the class Math. Therfore to reference the pow() method you would need to use like this:
Math.pow( base, order );

Also this method is returned a double type therefore your variable p need to defined as a double type unless you want cast it as an integer type.

If you don't want to use double as type then you would need to write your own pow() function like this:
   private static int pow( int base, int power )
   {
      int tmp = base;
      for ( int i = 1; i < power; i++ )
      {
          tmp *= base;
      }

      return tmp;
   }

Hope this help.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A programming problem for Data Types code_lover Intro Programming 1 May 13th, 2008 06:42 AM
Internet Cafe Programming Problem sharifa Pro Visual Basic 2005 0 February 16th, 2006 08:04 PM
Linear programming problem milk_vanilla Excel VBA 5 August 25th, 2005 09:06 AM
ACCESS Programming DELTE problem dvlnblk2000 Access 1 September 29th, 2004 07:50 AM
Problem while programming Ecard samir ASP.NET 1.0 and 1.1 Professional 1 December 14th, 2003 01:44 PM



All times are GMT -4. The time now is 01:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.