• Post Reply Bookmark Topic Watch Topic
  • New Topic

PROBLEM IN CODE  RSS feed

 
AJ sisodia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PROBLEM IN STATEMENT MARKED **



code:

import java.io.*;

class ByteArrayInputStreamReset {
public static void main(String args[]) throws IOException {
String tmp = "abc";
byte b[] = tmp.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(b);

for(int i=0; i<2; i++) {
int c;
while((c = in.read())!= -1) {
if(i==0) { ** //WHAT IS THE USE OF THIS LINE?WHY ARE WE DOING THIS
System.out.print((char)c);
} else {
System.out.print(Character.toUpperCase((char)c));
}
}
System.out.println();
in.reset();
}}}
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's your code, isn't it? So the question would be: Why did you put it there?

If you described what the code is supposed to do, we might try to guess why it's there.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also very bad code, because it doesn't convert properly between bytes and characters. Casting each byte to char isnot the way to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!