Reputation: 63
this is my first post. I am excited to a part of this community and I have been struggling with this problem for a while, so here goes:
In the following code:
if (j == 0)
{
if (!Arrays.equals(cipherData, c))
{
System.out.print("C: ");
for (int i = 0; i < encryptedData.length; i++)
System.out.print((char)cipherData[i]);
System.out.println();
}
}
The System.out.println()
method returns nothing at all. No line, or anything and I have no idea why. The goal is to print a blank line after printing the byte array is printed above when those if conditions are true.
Any help would be much appreciated and welcome.
Upvotes: 3
Views: 10283
Reputation: 718798
I have concerns about this:
System.out.print((char)cipherData[i]);
Assuming that cipherData
is an array of bytes, then casting a byte to a char
and printing it via a character stream is not likely to give pretty results. For a start, bytes that are less that 32 decimal will map to ASCII "control characters".
And also you may be printing the wrong array ... or using the length of the wrong array.
(But the explanation for your problem is that you need to call println
a second time to be a blank line. The first println is just terminating the line containing the ... umm ... "characters" from your cipher array.)
Upvotes: 1
Reputation: 4114
Before iterating for loop you can check length of encryptedData
System.out.println("encryptedData.length:: "+ encryptedData.length);
if encryptedData.length return greater than 1 then it will go into for loop.
You should debug step by step .
Upvotes: 1
Reputation: 2020
Sounds like the problem is that you have run a JVM without any standard output attached. Like on Windows, using javaw.exe to run a jar (which is the default, beware). Java.exe outputs to the console window, if you run it from a console, but javaw.exe does not. If you run the program from the file explorer window, even though you are using java.exe, you still won't get any standard out, because it's hidden by windows.
So, run the program in a command line window, and use java.exe, not javaw.exe.
Upvotes: 0
Reputation: 76898
System.out.print()
does not print a newline character.
You're outputting a bunch of stuff, then printing a newline with System.out.println()
. This causes the cursor to drop to the next line.
You need another one if you want a blank line after that.
Edit to add: I missed the fact that your for
loop conditional is ... different than the array you're printing. Did you mean for that to be the case?
Also, since you're possibly printing non-printable characters, it is completely plausible that you're causing the terminal to be in a state where the newline will no longer work.
What it comes down to is, println()
isn't broken. Either it's not getting called, or if you don't see a newline occur when it is called then the terminal is in a state where it no longer recognizes it.
Upvotes: 5
Reputation: 10997
Check
http://docs.oracle.com/javase/6/docs/api/java/io/PrintStream.html#println()
You may need System.out.print('\n')
;
Upvotes: 1