Professional Documents
Culture Documents
Java FAQ
Recent Topics
Register / Login
Author
hi guys..i have this code to count a character within a given source file..why wont it run/(it doesnt seem to compile either) import java.io.IOException; class Main { public static void main( String args[] ) { try { int count = 0; int ch = System.in.read(); while ( ch == '/') { count++; ch = System.in.read(); } System.out.println( "Total number of characters: " + count ); } catch ( IOException err ) { System.out.println("Unexpected error on input"); } } } any help? also i have this code (below) for calculating the lines in a source code (any random source code) how can i combine both codes (above and below) to produce code that will calculate the amount of logical lines in a source code? ive asked b4, given it ago, but im stuck at this point..can i get the answer??? thanks guys for your time and effort
www.coderanch.com/t/391399/java/java/wont-run
1/5
5/11/13
cheers tom
Marilyn de Queiroz Sheriff Joined: Jul 22, 2000 Posts: 9033
Originally posted by tom brownlee: sorry guys i forgot to add this code to my question previously:
view plain c opy to c lipboard print ?
10 0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 . 0 7 . 0 8 . 0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . 1 8 . 1 9 . 2 0 . 2 1 . 2 2 . 2 3 . 2 4 . 2 5 . 2 6 . 2 7 .
N ote: T ext c ontent in the c ode bloc ks is automatic ally word- wrapped
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt Marilyn de Queiroz Sheriff Joined: Jul 22, 2000 Posts: 9033
Originally posted by tom brownlee: just a thought...my previous question didnt ask one important thing.... how can i ask for a source code from the user to enable my code to be used. ive got this code..but how do i use it in cooperation with my other code?
view plain c opy to c lipboard print ?
10
N ote: T ext c ontent in the c ode bloc ks is automatic ally word- wrapped
0 1 . 0 2 . 0 3 . 0 4 . 0 5 . 0 6 .
2/5
5/11/13
0 9 . 1 0 . 1 1 . 1 2 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . 1 8 .
so i really suppose my entire question would be..how do i combine this code here, along with my code from my previous question to enable a user to enter a source code name and for the code to reply with the number of logical lines within that source code. make sense? once again thanks for the time on this guys. i really appreciate it. tom
Tom, It's easier to answer your questions if you keep your questions regarding the same thing in the same thread rather than three separate threads. I've moved them all here for you this time. Just hit the reply button and add your code or alternatively, you can hit the edit button and add it into the same post. [ April 08, 2002: Message edited by: Marilyn deQueiroz ]
10
Code #1 (class Main) will compile if you don't split your String between two lines. System.out.println("Unexpected error on input");
Perhaps it would be better if you had three methods rather than three classes.
10
www.coderanch.com/t/391399/java/java/wont-run
3/5
5/11/13
sorry marilyn i think it must of been the way i wrote the code out...it should be on one line...with that solved it still doesnt compile. any reason why? and when i use methods instead of classes it still doesnt work? any idea why?
Code #1 works for me ... Maybe you can give a bit more detail about the version of the compiler, os, compile error you get, etc. import java.io.IOException; class Main { public static void main( String args[] ) { try { int count = 0; int ch = System.in.read(); while ( ch == '/') { count++; ch = System.in.read(); } System.out.println( "Total number of characters: " + count ); } catch ( IOException err ) { System.out.println("Unexpected error on input"); } } } /Development/Java/tmp>javac Main.java /Development/Java/tmp>java Main /////// Total number of characters: 7
Code #2 works for me also: /Development/Java/tmp>javac Line2.java /Development/Java/tmp>java Line2 Main.java 24 Again, more information would be helpful ...
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
www.coderanch.com/t/391399/java/java/wont-run
Similar Threads
4/5
5/11/13
Similar Threads Loop & System.in.read weirdness! parseInt( ) System.in.read() - Abstract method? int and char Checked Exceptions - What did I wrong?
All times above are in your local time zone & format.T he current ranch time (not your local time) is May 11, 2013 06:14:37 .
www.coderanch.com/t/391399/java/java/wont-run
5/5