Buscar

AulaPratica-05

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

//EXERCICIO 16
import javax.swing.JOptionPane;
public class Exercicio16 {
	public static void main (String args[]) {
		int valor, quantPosit=0, somaPosit=0, quantNegat=0, somaNegat=0;
		
		for (int i = 0; i < 15; i++) {
			valor = Integer.parseInt(JOptionPane.showInputDialog("Digite o " + (i+1) + "º valor"));
			if (valor > 0) {
				quantPosit ++;	
				somaPosit += valor;
			}
			else if (valor < 0){
				quantNegat ++;	
				somaNegat += valor;
			}
		}
		
		JOptionPane.showMessageDialog(null, "a) A quantidade de números positivos: " + quantPosit + "\nb) A soma dos números positivos: " + somaPosit + "\nc) A quantidade de números negativos: " + quantNegat + "\nd) A soma dos númeos negativos: " + somaNegat, "RESULTADO", JOptionPane.INFORMATION_MESSAGE);
	}
}
//EXERCICIO 17
import javax.swing.JOptionPane;
public class Exercicio17 {
	public static void main (String args[]) {
		int quant = Integer.parseInt(JOptionPane.showInputDialog("Informe a quantidade de idades"));
		int idade = Integer.parseInt(JOptionPane.showInputDialog("Digite a 1ª idade"));
		
		int menor = idade, maior = idade, numIdade = idade;
		double media;
		
		for (int i = 1; i < quant; i++) {
			idade = Integer.parseInt(JOptionPane.showInputDialog("Digite a " + (i+1) + "º idade"));
			if (idade > maior) {
				maior = idade;
			}
			if (idade < menor){
				menor = idade;
			}
			numIdade += idade;
		}
		media = numIdade/quant;
		
		JOptionPane.showMessageDialog(null, "a) A maior idade: " + maior + "\nb) A menor idade: " + menor + "\nc) A Idade média: " + media, "RESULTADO", JOptionPane.INFORMATION_MESSAGE);
	}
}
//EXERCICIO 18 - 1ª forma
import javax.swing.JOptionPane;
public class Exercicio18 {
	public static void main(String args[]){
		int quant, quadra, cubo;
		String iStr, quadraStr, cuboStr, resp = "";
		quant = Integer.parseInt(JOptionPane.showInputDialog("Informe a quantidade de valores"));
		
		for (int i = 0; i < quant; i++) {
			quadra = (int) Math.pow(i, 2);
			cubo = (int) Math.pow(i, 3);
			iStr = ("\n ").concat(Integer.toString(i));
			quadraStr = (" ").concat(Integer.toString(quadra));
			cuboStr = (" ").concat(Integer.toString(cubo));
			
			resp += iStr.concat(quadraStr).concat(cuboStr);
		}
		
		JOptionPane.showMessageDialog(null, "Número Quadrado Cubo" + resp, "RESULTADO", JOptionPane.INFORMATION_MESSAGE);
	}
}
//EXERCICIO 18 - 2ª forma
import javax.swing.JOptionPane;
public class Exercicio18 {
	public static void main(String args[]){
		int quant;
		String resp = "Número Quadrado Cubo";
		quant = Integer.parseInt(JOptionPane.showInputDialog("Informe a quantidade de valores"));
		
		for (int i = 0; i < quant; i++) {
			resp += "\n " + i + " " + Math.pow(i, 2) + " " + Math.pow(i, 3) ;
		}
		
		JOptionPane.showMessageDialog(null, resp, "RESULTADO", JOptionPane.INFORMATION_MESSAGE);
	}
}

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Outros materiais