EXERCÍCIOS
RESOLVIDOS
EM JAVA
Autor: Cleiton dos Santos
import javax.swing.JOptionPane;
/**
*
* @author Cleiton
* 4) faça um programa que receba 4 notas de um aluno e mostre a média
*/
public class Calcula_media {
public static void main(String args[]){
float nota1, nota2, nota3, nota4, media;
nota1 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 1ª nota: "));
nota2 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 2ª nota: "));
nota3 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 3ª nota: "));
nota4 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 4ª nota: "));
media = (nota1+nota2+nota3+nota4)/4;
System.out.println("A média é: " + media);
}
}
import javax.swing.JOptionPane;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Cleiton
* 5) faça um programa que receba a idade de uma
* pessoa e mostre se é maior ou menor de idade
*/
public class Maior_idade {
public static void main(String args[]){
int idade;
idade = Integer.parseInt(JOptionPane.showInputDialog("Informe a idade: "));
if(idade >= 18){
System.out.println("É maior de idade");
}
else{
System.out.println("É menor de idade");
}
}
}
import javax.swing.JOptionPane;
/**
*
* @author Cleiton
*
2) faça um programa que receba 10 valores e mostre os pares
*/
public class Mostra_par {
public static void main(String args[]){
int numero, i;
for(i=0; i<10; i++){
numero = Integer.parseInt(JOptionPane.showInputDialog("Escreva o " + (i+1)+"°
número:"));
if(numero % 2 ==0){
System.out.println(numero + " é par");
}
}
}
}
import javax.swing.JOptionPane;
/**
*
* @author Cleiton
* 3) faça um programa que receba 10 valores e some-os
*/
public class Soma_10valores {
public static void main(String args[]){
int numero, soma=0, i;
for(i=0; i<10; i++){
numero = Integer.parseInt(JOptionPane.showInputDialog("Informe o "+(i+1)+ "°
número: "));
soma = soma + numero;
}
}
}
import javax.swing.JOptionPane;
/**
*
* @author Cleiton
*
1) faça um programa que receba 1 valor inteiro e mostre sua tabuada
*/
public class Tabuada {
public static void main(String args[]){
int i, numero;
numero = Integer.parseInt(JOptionPane.showInputDialog("Informe o número: "));
for(i=0; i<=10; i++){
System.out.println(numero + " X " + i + " = " + numero*i);
}
}
}

Exercicios java2016 - resolvidos

  • 1.
  • 2.
    import javax.swing.JOptionPane; /** * * @authorCleiton * 4) faça um programa que receba 4 notas de um aluno e mostre a média */ public class Calcula_media { public static void main(String args[]){ float nota1, nota2, nota3, nota4, media; nota1 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 1ª nota: ")); nota2 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 2ª nota: ")); nota3 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 3ª nota: ")); nota4 = Float.parseFloat(JOptionPane.showInputDialog("Informe a 4ª nota: ")); media = (nota1+nota2+nota3+nota4)/4; System.out.println("A média é: " + media); } }
  • 3.
    import javax.swing.JOptionPane; /* * Tochange this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Cleiton * 5) faça um programa que receba a idade de uma * pessoa e mostre se é maior ou menor de idade */ public class Maior_idade { public static void main(String args[]){ int idade; idade = Integer.parseInt(JOptionPane.showInputDialog("Informe a idade: ")); if(idade >= 18){ System.out.println("É maior de idade"); } else{ System.out.println("É menor de idade"); } } }
  • 4.
    import javax.swing.JOptionPane; /** * * @authorCleiton * 2) faça um programa que receba 10 valores e mostre os pares */ public class Mostra_par { public static void main(String args[]){ int numero, i; for(i=0; i<10; i++){ numero = Integer.parseInt(JOptionPane.showInputDialog("Escreva o " + (i+1)+"° número:")); if(numero % 2 ==0){ System.out.println(numero + " é par"); } } } }
  • 5.
    import javax.swing.JOptionPane; /** * * @authorCleiton * 3) faça um programa que receba 10 valores e some-os */ public class Soma_10valores { public static void main(String args[]){ int numero, soma=0, i; for(i=0; i<10; i++){ numero = Integer.parseInt(JOptionPane.showInputDialog("Informe o "+(i+1)+ "° número: ")); soma = soma + numero; } } }
  • 6.
    import javax.swing.JOptionPane; /** * * @authorCleiton * 1) faça um programa que receba 1 valor inteiro e mostre sua tabuada */ public class Tabuada { public static void main(String args[]){ int i, numero; numero = Integer.parseInt(JOptionPane.showInputDialog("Informe o número: ")); for(i=0; i<=10; i++){ System.out.println(numero + " X " + i + " = " + numero*i); } } }