Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/acenelio/curso-algoritmos/blob/master/java/soma_vetor.java #5

Open
ricardoaraujoramos opened this issue May 5, 2023 · 1 comment

Comments

@ricardoaraujoramos
Copy link

soma_vetor.java

Não precisa de 3 For para fazer esse exercício segue minha sugestão menor

public static void main(String[] args) {
Locale.setDefault(Locale.US);
Scanner sc = new Scanner(System.in);

	System.out.printf("Quantos numeros voce vai digitar? ");
	int n = sc.nextInt();
	double[] vetor = new double[n];
	
	for (int i=0; i<n; i++) {
		System.out.printf("Digite um numero: ");
		vetor[i] = sc.nextDouble();
	}
	
	double soma=0.0;
	System.out.printf("%nVALORES = ");		
	
	for(int i=0; i<n; i++) {
		System.out.printf(" " + vetor[i]);
		soma += vetor[i];			
	}
	
	System.out.println("\nSOMA = " + soma);
	double media = soma / n;
	System.out.println("MEDIA = " + media);
	
	sc.close();		
}
@Clairtonlm
Copy link

Muito bom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants