• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PROBLEM IN CODE

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}}}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic