Results 1 to 8 of 8
Thread: Print method
- 03-01-2013, 02:04 PM #1
Member
- Join Date
- Feb 2013
- Location
- The Netherlands
- Posts
- 17
- Rep Power
- 0
Print method
Hey i'm working with methods atm and I can't figure out what is going wrong here.
[Java] Error java - Pastebin.com
I want to be able to just call print("Hello, world!"); anywhere i want instead of the long versionLast edited by phantomcraft; 03-01-2013 at 02:07 PM.
- 03-01-2013, 02:10 PM #2
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: Print method
Original code:
The array initializer should be empty:Java Code:public static void print (String[s] args){ System.out.println(s); }
Please don't use pastebin to show code. Just use [code][/code] tags to post code.Java Code:public static void print (String[] args){ System.out.println(args[0]); }
- 03-01-2013, 02:12 PM #3
Member
- Join Date
- Feb 2013
- Location
- The Netherlands
- Posts
- 17
- Rep Power
- 0
Re: Print method
Thanks but I can't print my int's with it
- 03-01-2013, 02:25 PM #4
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: Print method
So, here's what you do next:
1) Copy your Java code to the clipboard
2) Click "Reply to thread" under this message
3) Type: [code]
4) Paste your code from the clipboard
5) Type: [/code]
6) Describe what your actual output is
7) Describe what your expected output is
8) If you have any exceptions, please feel free to include those in your reply as well
Remember we are programmers, not magicians with a crystal ball that read your mind...
- 03-01-2013, 03:03 PM #5
Member
- Join Date
- Feb 2013
- Location
- The Netherlands
- Posts
- 17
- Rep Power
- 0
Re: Print method
OutputJava Code:package test; public class Test { /** * @param args the command line arguments */ public static void main(String[] args) { int a = 3; int b = 5; int c = 10; print(c); } public static void print (String[s] args){ System.out.println(args[0]); } }
What i expected:Java Code:run: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: print at test.Test.main(Test.java:12) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
Java Code:run: 10 BUILD SUCCESSFUL (total time: 0 seconds)
- 03-01-2013, 03:39 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Print method
Well, first thing is...don't run code that doesn't compile.
In this case it doesn't compile because your print method accepts Strings, not ints.Please do not ask for code as refusal often offends.
- 03-01-2013, 03:41 PM #7
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
Re: Print method
Again, array initializers don't take parameters (at least not in this way).
Second, think about what information you want to pass to the method print. Is that a String array? No, it's an int. So make sure you actually accept an int:
Java Code:public static void print (int myNumber){ System.out.println( myNumber); }
- 03-01-2013, 03:55 PM #8
Member
- Join Date
- Feb 2013
- Location
- The Netherlands
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
One test print statement prints multiple times in extended paintComponent method
By hamster in forum New To JavaReplies: 4Last Post: 04-27-2012, 09:43 AM -
Javax Print Attribute for Selection Print Range
By rsawatzky in forum AWT / SwingReplies: 0Last Post: 04-26-2012, 12:14 AM -
using the toString method to print an array
By Wolfie in forum New To JavaReplies: 1Last Post: 03-06-2011, 10:41 PM -
print out error method for wrong args.
By Implode in forum New To JavaReplies: 9Last Post: 09-20-2009, 12:46 PM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks