(URI) Preenchimento de Vetor II - Solução

import java.io.*;
import java.util.*;

class Main  {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int valor = leitor(br);
       
        int imprime = 0;
        for (int i = 0; i < 1000; i++) {
            bw.write("N["+i+"] = "+ imprime +"\n");

            if (++imprime == valor) {
                imprime = 0;
            }
        }

        bw.flush();       
        bw.close();
    }

    static int leitor(BufferedReader br) throws NumberFormatException, IOException {
       int n;
       int resp = 0;

       while (true) {
           n = br.read();
           if (n >= '0' && n <= '9') break;

       }
       while (true) {
           resp = resp*10 + n-'0';
           n = br.read();
           if (n < '0' || n > '9') break;
       }

       return resp;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução