p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Java Basics (http://p2p.wrox.com/forumdisplay.php?f=199)
-   -   Source Code (http://p2p.wrox.com/showthread.php?t=38110)

nappydyno234 February 6th, 2006 11:24 PM

Source Code
 
I am trying to create source code that outputs my name and the pow(x,y) function where x and y are inputed and the power is outputted after my name. I have tried various things, but nothing seems to work. Does anyone have any basic pseudocode, or even source code that could be of use?

RahulSapkal February 7th, 2006 12:33 AM

There are various ways to do this. You can do this using Graphics2D.
If you want to do this using null layout, look at this absolute positioning example, See the demonstration at the end.

http://www.javareference.com/jrexamp...mple.jsp?id=26

Thanks,
Rahul

rahul@javareference.com
--------------------------
http://www.javareference.com

nappydyno234 February 7th, 2006 10:20 AM

I created my program, and it looks like this:

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);
    }
}

When I go to compile, it comes up with this:

power.java:7: ')' expected
     System.out.println("Java power" base order);
                                     ^
1 error

I am new at this, so I dont quite understand what the error i...if anyone out there knows, I would appreciate it greatly...




nappydyno234 February 7th, 2006 10:30 AM

I figured out that initial error, but I received three more errors for the following source 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);
    }
}

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.





ShafiChaudhry February 22nd, 2006 07:32 AM

You are missing import statement. Try the following code. It will work; however use of System.in needs thorough knowledge of streams/buffers/channels.

import static java.lang.Math.*;
public class Test {
public static void main(String[] args) {
int base = 2;
int power = 5;
System.out.println(base+" power "+ power + " = "+pow(2,5));
}
}

malli_kv2 March 20th, 2007 11:42 PM

u get error because in java the fileds must be intlized.
and u try every time in System.out.println the concate operator is used

K.Mallikarjunarao

zhangzhangt March 25th, 2007 06:49 AM

look..



All times are GMT -4. The time now is 08:03 AM.

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