Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.math.BigInteger;
- public class Main
- {
- public static void main(String[] coelhinhos)
- {
- Exercicios e = new Exercicios();
- e.ex4();
- }
- }
- class Exercicios
- {
- void ex1()
- {
- int var = 5;
- while(var < 69)
- {
- BigInteger fat = new BigInteger("1");
- for(int i = 2; i <= var; i++)
- {
- fat = fat.multiply(BigInteger.valueOf(i));
- }
- System.out.println("Fatorial de " + var + " eh " + fat.abs());
- switch(var)
- {
- case 5: var = 12; break;
- case 12: var = 49; break;
- case 49: var = 69; break;
- }
- }
- }
- void ex2()
- {
- /* a execucao termina quando receber um 0 */
- int cont = 0; // quantidade de numeros lidos
- Scanner t = new Scanner(System.in);
- float var = t.nextFloat();
- float media = var;
- if (var != 0) cont++;
- while (var != 0)
- {
- var = t.nextFloat();
- if (var != 0)
- {
- media += var;
- cont++;
- }
- }
- media /= cont;
- System.out.println("A media dos " + cont + " numeros eh " + media);
- }
- void ex3()
- {
- }
- void ex4()
- {
- Scanner t = new Scanner(System.in);
- float a = t.nextFloat();
- float b = t.nextFloat();
- String op = t.nextLine();
- float res = -1;
- boolean flag = false;
- switch(op.charAt(0))
- {
- case '+': res = a+b; flag = true; break;
- case '-': res = a-b; flag = true; break;
- case '*': res = a*b; flag = true; break;
- case '/': res = a/b; flag = true; break;
- default: System.out.println("nope");
- }
- if(flag)
- {
- System.out.println(a + op + b + " = " + " " + res);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment