(URI) Substituição em Vetor I - 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));
for (int i = 0; i < 10; i++) {
int valor = leitor(br);
if (valor <= 0) {
valor = 1;
}
bw.write("X["+i+"] = "+ valor +"\n");
}
bw.flush();
bw.close();
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
int sinal = 1;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
if (n == '-') sinal = -1;
if (n == '+') sinal = 1;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp*sinal;
}
}
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));
for (int i = 0; i < 10; i++) {
int valor = leitor(br);
if (valor <= 0) {
valor = 1;
}
bw.write("X["+i+"] = "+ valor +"\n");
}
bw.flush();
bw.close();
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
int sinal = 1;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
if (n == '-') sinal = -1;
if (n == '+') sinal = 1;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp*sinal;
}
}
Comments
Post a Comment