Jump to content
Fórum Script Brasil
  • 0

Problema em java


Same0302

Question

1 answer to this question

Recommended Posts

  • 0
package math;

import java.util.ArrayList;
import java.util.List;

public class MultiplosSB {

	public static void main(String[] args) {
		List<Integer> numeros = new ArrayList<Integer>();
		int n = 0;
		for (int i = 0; i < 30; i++) {
			n = (int) (Math.random() * 1000);
			numeros.add(n);
		}
		List<Integer> nd3 = new ArrayList<Integer>();
		List<Integer> nd5 = new ArrayList<Integer>();
		for (Integer x : numeros) {
			if (x % 3 == 0) {
				nd3.add(x);
			}
			if (x % 5 == 0) {
				nd5.add(x);
			}
		}
		Integer sm = 0;
		for (Integer y : nd3) {
			sm += y;
		}
		System.out.println("Quantidade de valores multiplos de 5: " + nd5.size());
		System.out.println("Média dos valores multiplos de 3: " + sm / nd3.size());
	}

}

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148691
    • Total Posts
      644530
×
×
  • Create New...