Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2006, 09:19 AM
Registered User
 
Join Date: Feb 2006
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.

 
Old February 9th, 2006, 05:41 PM
Registered User
 
Join Date: Feb 2006
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);

 
Old February 11th, 2006, 12:27 PM
Authorized User
 
Join Date: Jan 2006
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.






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





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