Skip to content

Commit

Permalink
added exercicios aula 19 - vetores - netbeans
Browse files Browse the repository at this point in the history
  • Loading branch information
loiane committed Mar 24, 2015
1 parent 5b7f5a9 commit b41a1a0
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/
package com.loiane.cursojava.aula19.labs;

import java.util.Scanner;

/**
*
* @author loiane
*/
public class Exer19 {

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

double[] notas1 = new double[10];
double[] notas2 = new double[notas1.length];
double[] resultados = new double[notas1.length];

for (int i=0; i<notas1.length; i++){

System.out.println("Entre com a nota 1 do aluno " + (i+1));
notas1[i] = scan.nextDouble();

System.out.println("Entre com a nota 2 do aluno " + (i+1));
notas2[i] = scan.nextDouble();

resultados[i] = (notas1[i] + notas2[i]) / 2;
}

System.out.print("Notas 1 = ");
for (int i=0; i<notas1.length; i++){
System.out.print(notas1[i] + " ");
}
System.out.println();

System.out.print("Notas 2 = ");
for (int i=0; i<notas2.length; i++){
System.out.print(notas2[i] + " ");
}
System.out.println();

System.out.println("Resultados:");
for (int i=0; i<resultados.length; i++){

if (resultados[i] >= 7){
System.out.println(resultados[i] + " - Aprovado");
} else {
System.out.println(resultados[i] + " - Reprovado");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.
*/
package com.loiane.cursojava.aula19.labs;

import java.util.Scanner;

/**
*
* @author loiane
*/
public class Exer24 {

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[10];

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com um número para a posição " + i);
vetorA[i] = scan.nextInt();

}


//1221
//i = 2

boolean palindromo = true;
for (int i=0; i<(vetorA.length/2); i++){

if (vetorA[i] != vetorA[vetorA.length - 1 - i]){
palindromo = false;
break;
}
}

System.out.print("Vetor A = ");
for (int i=0; i<vetorA.length; i++){
System.out.print(vetorA[i] + " ");
}
System.out.println();

if (palindromo){
System.out.println("Palindromo");
} else {
System.out.println("Não é palindromo");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,28 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[10];
int[] vetorB = new int[vetorA.length];

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com o valor da posição " + i);
vetorA[i] = scan.nextInt();

vetorB[vetorA.length - i - 1] = vetorA[i];
}

System.out.print("Vetor A = ");
for (int i=0; i<vetorA.length; i++){
System.out.print(vetorA[i] + " ");
}
System.out.println();


System.out.print("Vetor B = ");
for (int i=0; i<vetorB.length; i++){
System.out.print(vetorB[i] + " ");
}
System.out.println();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,43 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[10];
int[] vetorB = new int[vetorA.length];
int[] vetorC = new int[vetorA.length * 2];

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com o valor da posição A - " + i);
vetorA[i] = scan.nextInt();

vetorC[i] = vetorA[i];
}

for (int i=0; i<vetorB.length; i++){

System.out.println("Entre com o valor da posição B - " + i);
vetorB[i] = scan.nextInt();

vetorC[vetorA.length + i] = vetorB[i];
}

System.out.print("Vetor A = ");
for (int i=0; i<vetorA.length; i++){
System.out.print(vetorA[i] + " ");
}
System.out.println();


System.out.print("Vetor B = ");
for (int i=0; i<vetorB.length; i++){
System.out.print(vetorB[i] + " ");
}
System.out.println();

System.out.print("Vetor C = ");
for (int i=0; i<vetorC.length; i++){
System.out.print(vetorC[i] + " ");
}
System.out.println();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,47 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[20];
int[] vetorB = new int[vetorA.length]; //pares
int[] vetorC = new int[vetorA.length]; //impares

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com o valor da posição A - " + i);
vetorA[i] = scan.nextInt();
}

int posB = 0;
int posC = 0;

for (int i=0; i<vetorA.length; i++){

if (vetorA[i] % 2 == 0){
vetorB[posB] = vetorA[i];
posB++;
} else {
vetorC[posC] = vetorA[i];
posC++;
}
}

System.out.print("Vetor A = ");
for (int i=0; i<vetorA.length; i++){
System.out.print(vetorA[i] + " ");
}
System.out.println();


System.out.print("Vetor B = ");
for (int i=0; i<posB; i++){
System.out.print(vetorB[i] + " ");
}
System.out.println();

System.out.print("Vetor C = ");
for (int i=0; i<posC; i++){
System.out.print(vetorC[i] + " ");
}
System.out.println();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,24 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[5];

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com o valor da posição A - " + i);
vetorA[i] = scan.nextInt();
}

for (int i=0; i<vetorA.length; i++){

System.out.println("Tabuada de " + vetorA[i]);

for (int j=1; j<=10; j++){

System.out.println(j + " * " + vetorA[i] + " = " + (vetorA[i]*j));
}

System.out.println();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,35 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[5];

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com o valor da posição A - " + i);
vetorA[i] = scan.nextInt();
}

boolean primo;
String msg;

for (int i=0; i<vetorA.length; i++){

primo = true;
for (int j=2; j<vetorA[i]; j++){
if (vetorA[i] % j == 0){
primo = false;
break;
}
}

msg = "";
if (primo){
msg = " primo";
} else {
msg = " não é primo";
}

System.out.println(vetorA[i] + msg);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,25 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[10];

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com o valor da posição A - " + i);
vetorA[i] = scan.nextInt();
}

for (int i=0; i<vetorA.length; i++){

System.out.println("Analizando o número " + vetorA[i]);

for (int j=2; j<vetorA[i]; j++){
if (j % 2 == 0){
System.out.println(j + " é par");
}
}

System.out.println();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,25 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int[] vetorA = new int[10];

for (int i=0; i<vetorA.length; i++){

System.out.println("Entre com o valor da posição A - " + i);
vetorA[i] = scan.nextInt();
}

for (int i=0; i<vetorA.length; i++){

System.out.println("Analizando o número " + vetorA[i]);

for (int j=1; j<vetorA[i]; j++){
if (vetorA[i] % j == 0){
System.out.println(j + " é divisor");
}
}

System.out.println();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ public static void main(String[] args){

Scanner scan = new Scanner(System.in);

double[] vetorA = new double[11];

for (int i=0; i<vetorA.length; i++){

vetorA[i] = Math.pow(2, i);
}

System.out.print("Vetor A = ");
for (int i=0; i<vetorA.length; i++){
System.out.print(vetorA[i] + " ");
}
System.out.println();
}
}
Loading

0 comments on commit b41a1a0

Please sign in to comment.