Escolar Documentos
Profissional Documentos
Cultura Documentos
import java.util.Scanner;
public class idade {
soma+=n;
cont++;
}
double media= (soma / cont);
System.out.print(String.format("%.2f", media));
}
EX.2
import java.util.Scanner;
if (sexo == 1) {
qtMulheres++;
} else if (sexo == 2) {
qtHomens++;
somaH = somaH + altura;
} else {
System.out.println("Opção sexo inválido!");
}
if (altura > maior) {
maior = altura;
entrada.close();
}
}
EX.3
// Constroi a tabela
for(Farenheit = 50; Farenheit <= 150; Farenheit++){
oudOu
}
EX.4
double pc = 0.00;
double pv = 0.00;
double max = 1000.00;
double min = 1.00;
int x;
int l1 = 0;
int l2 = 0;
int ln = 0;
double lu;
pv = (Math.random()*(max-min+1)+min);
pc = (Math.random()*(max-min+1)+min);
lu = (pv/pc) * 100;
if (lu < 10){
l1 += 1;
}
else if (lu >= 10 && lu <= 20){
l2 += 1;
}
else{
ln += 1;
}
}
// exive (ou imprime) os resultados
System.out.println("menos 10% de lucro:" + l1);
System.out.println("entre 20% de lucro:" + l2);
System.out.println("mais de 20% de lucro:" + ln);
}
}
EX.5
int ContadorAnos = 0;
ContadorAnos++;
}
}
EX.6
import java.util.Scanner;
double MassaInicial = 0;
double MassaFinal = 0;
int Segundos = 0;
Scanner Entrada = new Scanner(System.in);
MassaInicial = Double.parseDouble(Entrada.nextLine());
MassaFinal = MassaInicial;
MassaFinal /= 2;
Segundos += 50;
}
EX.7
double alunosM;
int max;
int min;
int nt = 0;
int na = 0;
double poa = 0;
double qa = 0;
double pc = 0;
for (nt = 0; nt < totalturmas; nt++){
max = 60;
min = 15;
alunosM = (Math.random()*(max-min+1)+min);
poa = (Math.random()*(max-min+1)+min);
if (poa >= 1){
qa = 100/alunosM;
pc += qa;
}
}
System.out.println(Math.round(pc) + "%");
pc = 0;
}
}
}
EX.8
double inputsex;
double inputopi;
else{
nf += 1;
inputopi = (Math.random()*(max-min+1)+min);
if (inputopi <= 1){
nmneg += 1;
nneg += 1;
}
}
//calcula os porcentuais
}
double pfpos = nfpos*100/nf;
double pmneg = nmneg*100/nm;
//resultados impressos
EX.9
package demo;
import java.util.Scanner;
// resultados
System.out.println(Math.round(p4)+"%");
System.out.println(Math.round(p5)+"%");
System.out.println(Math.round(p7)+"%");
System.out.println(Math.round(p12)+"%");
}
}
EX.11
long codcurso=1;
long max = 30;
long min = 0;
long rand = Math.round(Math.random()*(max-min+1)+min);
long nvagas = 0;
long candM = 0;
long candF = 0;
long candV = 0;
long pcF = 0;
//Inicialização para ver o maior numero de candidatos por vagas, acumuladores e condicoes
iniciais
nvagas = Math.round(Math.random()*(max-min+1)+min);
max = nvagas;
min = 0;
candM = Math.round(Math.random()*((max-1)-min+1)+min);
max = max - candM;
min = 0;
candF = Math.round(Math.random()*(max-min+1)+min);
max = 30;
min = 0;
}
}
EX.12
int nalunos = 0;
long matricula=10;
long nota1 = 0;
long nota2 = 0;
long nota3 = 0;
long notafinal = 0;
long notapos = 60;
long naulas = 0;
long naluasfreq = 0;
long notamturma = 0;
int alunosReprovados = 0;
int alunosausentes =0;
long max = 0;
long min = 0;
long maiornota = 0;
long menornota = 100;
max = 99999;
min = 11111;
matricula = Math.round(Math.random()*((max)-min+1)+min);
System.out.println("SUA MATRICULA É: " + matricula);
max = 100;
min = 5;
nota1 = Math.round(Math.random()*((max)-min+1)+min);
System.out.println("ALUNO REPROVADO");
alunosReprovados += 1;
}
notamturma = notamturma/nalunos;
System.out.println("MAIOR NOTA: " + maiornota);
System.out.println("MENOR NOTA: " + menornota);
System.out.println(alunosReprovados + " ALUNOS REPROVADOS");
System.out.println("MÉDIA DA TURMA " + notamturma);
System.out.println(alunosausentes + " ALUNOS REPROVADOS POR FREQUENCIA ");
}
}
EX.13
long pKw=10;
long nconsumidor=1;
long qtdKw= 0;
long tipoconsu;
int max = 100;
int min = 0;
long mcons = 0;
long mincons = 10000;
long maxr = 0;
long maxc = 0;
long maxi = 0;
long cont = 0;
long soma = 0;
nconsumidor = Math.round(Math.random()*((max)-min+1)+min);
for (nconsumidor = 1; nconsumidor != 0; nconsumidor =
Math.round(Math.random()*((max)-min+1)+min)){
max = 100;
min = 0;
pKw = Math.round(Math.random()*((max)-min+1)+min);
qtdKw = Math.round(Math.random()*((max)-min+1)+min);
//delcarando as variaveis
long m1= 0;
long m2= 0;
long v1 = 20;
long v2 = 30;
int v3 = 40;
int v4 = 50;
long v5 = 60;
long v6 = 70;
long v7 = 80;
long max = 30;
long min = 1;
long tnes = 0;
}
}
}
EX.15
double bm = 15.00;
long max = 30;
long min = 1;
long ntran = Math.round(Math.random()*(max-min+1)+min);
double bmd = 5.00;
}
}
EX.16
long Ni=1;
long i=0;
long s= 0;
long exp = 0;
long nf = 0; // Candidatos do sexo masculino
long nm = 0; // Candidatos do sexo feminino
long im45 = 0; Média de homens com mais de 45 anos
long nmexp = 0; // Média de mulheres com menos de 35 e com experiencia
long mif = 99;
long max = 1000;
long min = 0;
long x = 0;
Ni = Math.round(Math.random()*((max)-min+1)+min);
max = 90;
min = 19;
i = Math.round(Math.random()*((max)-min+1)+min);
max = 2;
min = 0;
s = Math.round(Math.random()*((max)-min+1)+min);
exp = Math.round(Math.random()*((max)-min+1)+min);
if (s > 0){
nf += 1;
if (i < 35 && exp > 0){
nmexp += 1;
if (i < mif){
mif = i;
}
}
EX.17
//declarando as variaveis
//impressão
double x = 0;
for (x = 5.0; x >= 1.5; x -= dip){
pi -= dip;
iv += 26;
//Impressao
EX.18
vt = tf1 - te;
if (vt < 3.0){
p += 100;
}
else if (vt >= 3 && vt <= 5){
p += 80;
}
else if (vt > 5){
p += 80-(vt-5)/5;
}
te = Math.round(Math.random()*((max)-min+1)+min);
vt = tf2 - te;
if (vt < 3.0){
p += 100;
}
else if (vt >= 3 && vt <= 5){
p += 80;
}
else if (vt > 5){
p += 80-(vt-5)/5;
}
te = Math.round(Math.random()*((max)-min+1)+min);
vt = tf3 - te;
if (vt < 3.0){
p += 100;
}
else if (vt >= 3 && vt <= 5){
p += 80;
}
else if (vt > 5){
p += 80-(vt-5)/5;
}
if (p >= mp){
mp = p;
eqv = ni;
}
max = 9999;
min = 9950;
p = 0;
}
}
}
EX.19
//declarando as variaveis
sf = Math.round(Math.random()*((max)-min+1)+min);
long x = 0;
for (x = 0; x <= ne; x++){
max = 9999;
min = 0001;
ni = Math.round(Math.random()*((max)-min+1)+min);
max = 45;
min = 1;
nc = Math.round(Math.random()*((max)-min+1)+min);
if (nc >= 10){
nc = 100 * nc;
}
else {
nc = 50 * nc;
}
npb = Math.round(Math.random()*((max)-min+1)+min);
if (npb >= 20){
npb = 40* npb;
}
else {
npb = 20* npb;
}
//Calcudo do INPS
sb = sf + nc + npb;
sf = sf - (sf * 8/100);
sl = sf + nc + npb;
if (sl >= 3000.00){
sl = sl - (sl * 5/100);
}
System.out.println("---Numero da inscricao – Salario Bruto/Liquido---");
EX.20
//declarando as variaveis
max = 31;
min = 1;
dia = Math.round(Math.random()*((max)-min+1)+min);
max = 12;
min = 1;
mes = Math.round(Math.random()*((max)-min+1)+min);
max = 2099;
min = 1900;
ano = Math.round(Math.random()*((max)-min+1)+min);
D = dia;
A = ano%100;
S = ano%10000 - ano%100;
if (mes < 3){
M = mes + 10;
}
else{
M = mes - 2;
}
Ds = ( (2.6*(M - 0.2)/1) + D + A + (A/4) + (S/4) -2 * S )% 7;
System.out.println("DIA: " + dia + "MES: " + mes + "ANO: " + ano + "Dia da semana:
"+Math.round(Ds * -1));
}
}
}
EX.21
}
mpm = mpm/cm;
mpf = npf/cf;
System.out.println("Folha mensal: "+tmen);
System.out.println("Total de peças por mes: "+tpf);
System.out.println("Media peças de por Homens: "+mpm);
System.out.println("Média peças de Mulhores: "+mpf);
System.out.println("Operadio com maior salario"+nmsal);
System.out.println("Salário do operário(a): "+msal);
}
}
EX.22
long selector = 0;
long x = 0;
for (x = 1; x <= nop; x++){
selector = Math.round(Math.random()*((max)-min+1)+min);
if (selector >= 500){
lux += lux;
}
else {
lst += lst;
}
}
System.out.println("O lucro total é: " + Math.round(lst + lux));
}
}
EX.23
EX.24
//declarando valores
long A = 1;
long B = 1;
long S = 0;
long x = 0;
S += A/B;
for (x = A; x <= 97; x += 2){
A += 2;
B += 1;
S += A/B;
}
//impressao do resultado
EX.25
long A = 2;
long fA = 1;
long B = 50;
long S = 0;
long x = 0;
S += Math.round(Math.pow(A, fA)/B);
EX.26
long B = 37;
long R = 38;
long A = 1;
long M = B * R/A;
long x = 0;
//Impressão do resultado
long B = 1;
long F = 1;
long A = 1;
long E = 1;
long fE = 3;
double M = 0;
long H = 1;
M += (B/F * H);
long x = 0;
//impressao do resultado
EX.28
long B = 1000;
long F = 1;
long A = 3;
long E = 1;
double M = 0;
long H = 1;
M += (B/F * H);
long x = 0;
//impressao do resultado
EX.29
long B = 480;
long F = 10;
long A = 5;
long E = 1;
double M = 0;
long H = 1;
M += (B/F * H);
long x = 0;
//impressao do resultado
EX.30
}
System.out.println("O valor de S é: " + M);
}
}
EX.31
long A = 4;
long D = 1;
long sD = 2;
long H = 1;
double M = 0;
long x = 0;
long y = 0;
}
System.out.println("O valor calculado é: " + M);
}
}
EX.42
//Recebendo as coordenadas
long d = 0;
long s = x1 + y1 + x2+y2;
for (s = (x1+y1+x2+y2); s != 0; s= (x1+y1+x2+y2)){
d = (x2 - x1) *2 + (y2 - y1) * 2;
//impressao do resultado
EX.43
//Recebendo as coordenadas
long a = Math.round(Math.random()*(max-min+1)+min);
System.out.println("Informe o valor de A: "+ a);
long b = Math.round(Math.random()*(max-min+1)+min);
System.out.println("Informe o valor de B: "+ b);
long c = Math.round(Math.random()*(max-min+1)+min);
System.out.println("Informe o valor de C: "+ c);
long d = Math.round(Math.random()*(max-min+1)+min);
System.out.println("Informe o valor de D: "+ d);
long u = Math.round(Math.random()*(max-min+1)+min);
System.out.println("Informe o valor de U: "+ u);
long v = Math.round(Math.random()*(max-min+1)+min);
System.out.println("Informe o valor de V: "+ v);
//calcolo da solucao X
long y = 0;
long x = 0;
//imprimendo os resultados
EX.44
//Recebendo os parametros
for (s = 1; s != 0; s = (a+b)){
a = Math.round(Math.random()*(max-min+1)+min);
b = Math.round(Math.random()*(max-min+1)+min);
y = (a*Math.round(Math.random()*(max-min+1)+min)) + b;
ba = a - b;
at = (ba * y)/2;
}
}
}
EX.45
long f = 0;
long x = 0;
long h = 0;
long g = 0;
long y = f + g;
y = f + g; //calculo de Y
//Impressão de resultados
System.out.println("Valor de Y : "+ y );
System.out.println("Valor de F : "+ f );
System.out.println("Valor de G : "+ g );
System.out.println("Valor de H : "+ h );
}
}
}
EX.46
double y;
double x;
x = 1;
y = 1;
x = STDIN_SCANNER.nextDouble();
y = STDIN_SCANNER.nextDouble();
System.out.println("INTERIOR");
} else {
System.out.println("INTERIOR");
System.out.println("EXTERIOR");
} else {
System.out.println("EXTERIOR");
}
EX.47
max = B -1;
A = Math.round(Math.random()*(max-min+1)+min);
long S = (A+B) * ((A+B)*(A+B));
//resultados
EX.48
double pi = Math.PI;
//resultados
N = Math.round(Math.random()*((max)-min+1)+min);
R = Math.round(Math.random()*((max)-min+1)+min);
//calcula a area
area = (R/2) * N;
//resultado
EX.50