|  | 
|  | 
| вернуться в форум | How to read input in Java? I know how to identify end of console in Pascal, C/C++, but in Java it's not working. Anybody knows?
 What is the bug in my code?
 
 import java.io.*;
 public class ACM1601 {
 
 public static void main(String[] args) throws IOException{
 
 
 boolean isNewSntc = true;
 String line="";
 int ch;
 while ((ch = System.in.read()) != -1) {
 if (isNewSntc){
 line += Character.toString((char)ch);
 isNewSntc = false;
 }
 else {
 line += Character.toString(lowerCase((char)ch));
 }
 if (ch == 46 || ch == 63 || ch == 33)
 isNewSntc = true;
 }
 
 System.out.println(line);
 }
 
 public static char lowerCase(char in) {
 if ((int)in > 64 && (int)in < 91)
 return (char) ((int)in + 32);
 return in;
 }
 }
 
 Edited by author 31.12.2013 22:26
 
 Edited by author 31.12.2013 22:26
Re: How to read input in Java? Does this work?
 import java.io.*;
 class CopyFirst {
 public static void main(String[] args) throws IOException {
 int ch;
 while ((ch = System.in.read()) != -1)
 System.out.print((char)ch);
 }
 }
 | 
 | 
|