-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx01.java
More file actions
41 lines (28 loc) · 922 Bytes
/
Copy pathEx01.java
File metadata and controls
41 lines (28 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
Escreva um programa que recebe como parâmetro um número inteiro n.
A função deve ler n valores do teclado e retornar quantos destes
valores são negativos.
*/
import java.util.Scanner;
public class Ex01 {
public static int qtdNeg (int n){
Scanner leia = new Scanner(System.in);
int i;
int n_atual;
int qtd_negativo = 0;
for (i=0; i<n; i++){
System.out.println(i+1+" numero: ");
n_atual = leia.nextInt();
if (n_atual < 0){
qtd_negativo +=1;
}
}
System.out.println("Quantidade de numeros negativos: " +qtd_negativo);
return qtd_negativo;
}
public static void main(String[] args) {
Scanner leia = new Scanner(System.in);
System.out.println("Digite a quantidade de n: ");
qtdNeg(leia.nextInt());
}
}