Error On System.out.println
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Java syntax error on `System.out.println()` method call [closed] up vote -1 down vote favorite 1 I'm sorry for the extremely short question, but i don't even know why i have this error: Syntax error on token "println", = expected after this token In this code: static long start = System.currentTimeMillis(); public void testSort5() { Random random = new Random(); int number; int[] arr = new int[1000]; for (int counter = 1; counter < 1000; counter++) { number = 1 + random.nextInt(1000); arr[counter] = number; } int[] actual = MergeSort.sort(arr); } long end = System.currentTimeMillis(); System.out.println("Execution time was " + (end - start) + " ms."); java syntax-error share|improve this question edited Mar 19 '12 at 2:13 user155407 asked Mar 19 '12 at 0:23 Vladislav Bogdanov 410258 closed as off-topic by Patrick Hofman, Martijn Pieters♦, dav_i, Stijn, Qantas 94 Heavy Aug 18 '14 at 11:48 This question appears to be off-topic. The users who voted to close gave this specific reason:"This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Patrick Hofman, Martijn Pieters, dav_i, StijnIf this question can be reworded to fit the rules in the help center, please edit the question. add a comment| 4 Answers 4 active oldest votes up vote 11 down vote You have statements outside your method body. share|improve this answer answered Mar 19 '12 at 0:25 Oliver Charlesworth 184k20365518 I already have like 50+ projects created in my current eclipse, yet I faced thise and passed by; Don't jusdge people, rough days can do more than this xD –Enissay Feb 1 at 20:22 add a comment| up vote 4 down vote Your last two lines: long end ... System.out.println... Appear to be outside of any method. You can't just run code outside of a m
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just http://stackoverflow.com/questions/9763584/java-syntax-error-on-system-out-println-method-call like you, helping each other. Join them; it only takes a minute: Sign up Syntax errors on token for System.out.println [closed] up vote 0 down vote favorite I'm making a class called Sphere and I want to prompt the user to input the Diameter and I keep getting this error in Eclipse for the part of http://stackoverflow.com/questions/23583580/syntax-errors-on-token-for-system-out-println code that is asking for input. Error: Multiple Markers at this line Syntax error on token(s), misplaced constructs(s) Syntax error on token ""Please enter diameter"", delete this token My code so far: import java.util.Scanner; import java.lang.Math; public class Sphere { public static void main(String[] args) { } public int diam; Scanner input = new Scanner(System.in); System.out.println("Please enter diameter"); //error on this line } java syntax-error println share|improve this question asked May 10 '14 at 16:28 pudge 1027 closed as off-topic by Hovercraft Full Of Eels, Luiggi Mendoza, jahroy, Reimeus, Simze May 10 '14 at 16:37 This question appears to be off-topic. The users who voted to close gave this specific reason:"This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before
This Site Careers Other all forums Forum: Beginning Java problem in System.out.println vinaykumar singh Greenhorn Posts: 13 posted 10 years ago hello all... i having a problem https://coderanch.com/t/402045/java/java/System-println in System.out.println(); see code and please guide me.(i m using Eclipse https://coderanch.com/t/453708/java/java/error-system-println 3.0,and also tried this code in diffrent editor) public class A { System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); } i have a another main class where i calling class A. get error in class A System.out.println(); Multipal markers at this line -Syntax error on token ""aaaaaa"", delete this token -Syntax error on error on Token(s), misplaced construct(s) ----------------------------------------------------------- if i write only public class A { System.out.println(); } getting -Syntax error on token "println", Identifier expected after this token ------------------------------------------------------------------------- and if i decleared main method in class A there is no error like public class A { public static void main(String args[]){ System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); } } -No Error ------------------------------------------------------------------------- please guide me why error on system.out.println this is happening. thanks in advance... vinay kumar singh fred rosenberger lowercase baba Bartender Posts: 12221 36 I like... posted 10 years ago In the first example, you can't have a statement that's not in a method. you could put the method in a constructor if you want it to print when the object is created, or you have to define a method like void printStuff(){ System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); } and then call that method on the object. in the second example, i think it's because there is no version of println that takes no argument - you have to pass it SOMETHING. and, if you change it to pass in a parameter, you'll be back at the first example. in your third example, you have an enclosing method and a valid call to the println method. [ January 17, 2006: Message edited by: fred rosenberger ] There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors Layne Lund Ranch Hand Posts: 3061 posted 10 years ago Originally post
This Site Careers Other all forums Forum: Beginning Java error in system.out.println cchetan jain Ranch Hand Posts: 30 posted 7 years ago class f { public static void main(String a[]) { System.out.print(null); } } why this gives an error..while when we use object in the argument for print ..it never gives an error?? please sort out this.. i m very curious about it? Campbell Ritchie Sheriff Posts: 50486 82 posted 7 years ago What error did you get? What do you think it means? Rob Spoor Sheriff Posts: 20695 68 I like... posted 7 years ago E:\f.java:5: reference to print is ambiguous, both method print(char[]) in java.io.PrintStream and method print(java.lang.String) in java.io.PrintStream match System.out.print(null); ^ 1 errorThe problem is that, as the compiler error tells you, there are (at least) two print methods that can accept null. Actually there are three; also print(Object). Now the compiler tries to find the most specific version of an overloaded method. Both char[] and String are sub types of Object, so that's why the third method is not considered. char[] and String are both too distinct for the compiler to choose for you. To fix this, specify the type by casting: System.out.println((String)null); SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6 How To Ask Questions How To Answer Questions Post Reply Bookmark Topic Watch Topic New Topic Similar Threads K&B page no 121 doubt definite assignment for loop not compiling Arrays doubt Doubt in Exceptions. All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter Contact Us | advertise | mobile view | Powered by JForum | Copyright © 1998-2016 Paul Wheaton