ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1601. AntiCAPS

How to read input in Java?
Posted by Nodir NAZAROV Komiljonovich 31 Dec 2013 21:59
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?
Posted by Nodir NAZAROV Komiljonovich 31 Dec 2013 22:05
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);
   }
}