exercicios java2016 - resolvidos

6

Click here to load reader

Upload: helda-matos

Post on 14-Apr-2017

228 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Exercicios java2016 - resolvidos

EXERCÍCIOS

RESOLVIDOS

EM JAVA

Autor: Cleiton dos Santos

Page 2: Exercicios java2016 - resolvidos

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);

}

}

Page 3: Exercicios java2016 - resolvidos

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");

}

}

}

Page 4: Exercicios java2016 - resolvidos

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");

}

}

}

}

Page 5: Exercicios java2016 - resolvidos

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;

}

}

}

Page 6: Exercicios java2016 - resolvidos

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);

}

}

}