Buscar

IFMT Exercicio Vetores e Matrizes em Java

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

IFMT/build.xml
 
 Builds, tests, and runs the project IFMT.
 
 
IFMT/manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
IFMT/nbproject/build-impl.xml
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must set src.dir
 Must set test.src.dir
 Must set build.dir
 Must set dist.dir
 Must set build.classes.dir
 Must set dist.javadoc.dir
 Must set build.test.classes.dir
 Must set build.test.results.dir
 Must set build.classes.excludes
 Must set dist.jar
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must set javac.includes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 No tests executed.
Must set JVM to use for profiling in profiler.info.jvm
 Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must select some files in the IDE or set javac.includes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 To run this application from the command line without Ant, try:
 
 java -jar "${dist.jar.resolved}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must select one file in the IDE or set run.class
 
 
 
 Must select one file in the IDE or set run.class
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must select one file in the IDE or set debug.class
 
 
 
 
 Must select one file in the IDE or set debug.class
 
 
 
 
 Must set fix.includes
 
 
 
 
 
 
 
 
 
 This target only works when run from inside the NetBeans IDE.
 
 
 
 
 
 
 
 
 Must select one file in the IDE or set profile.class
 This target only works when run from inside the NetBeans IDE.
 
 
 
 
 
 
 
 
 This target only works when run from inside the NetBeans IDE.
 
 
 
 
 
 
 
 
 
 
 
 
 This target only works when run from inside the NetBeans IDE.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must select one file in the IDE or set run.class
 
 
 
 
 
 Must select some files in the IDE or set test.includes
 
 
 
 
 Must select one file in the IDE or set run.class
 
 
 
 
 Must select one file in the IDE or set applet.url
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must select some files in the IDE or set javac.includes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Some tests failed; see details above.
 
 
 
 
 
 
 
 
 Must select some files in the IDE or set test.includes
 
 
 
 Some tests failed; see details above.
 
 
 
 Must select some files in the IDE or set test.class
 Must select some method in the IDE or set test.method
 
 
 
 Some tests failed; see details above.
 
 
 
 
 Must select one file in the IDE or set test.class
 
 
 
 Must select one
file in the IDE or set test.class
 Must select some method in the IDE or set test.method
 
 
 
 
 
 
 
 
 
 
 
 
 
 Must select one file in the IDE or set applet.url
 
 
 
 
 
 
 
 
 Must select one file in the IDE or set applet.url
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
IFMT/nbproject/genfiles.properties
build.xml.data.CRC32=9ea5a6a7
build.xml.script.CRC32=705c348c
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=9ea5a6a7
nbproject/build-impl.xml.script.CRC32=dd5c5bae
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
IFMT/nbproject/private/private.properties
compile.on.save=true
user.properties.file=/home/joao/.netbeans/8.0.2/build.properties
IFMT/nbproject/private/private.xml
 
 
 
 
 file:/home/joao/NetBeansProjects/FTMT/src/Exercicios.java
 
 
IFMT/nbproject/project.properties
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
 ${run.classpath}
debug.test.classpath=\
 ${run.test.classpath}
# Os arquivos em build.classes.dir que devem ser exclu\u00eddos do jar de distribui\u00e7\u00e3o
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/IFMT.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
 ${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
 ${javac.classpath}:\
 ${build.classes.dir}
javac.test.processorpath=\
 ${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=Exercicios
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
 ${javac.classpath}:\
 ${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
 ${javac.test.classpath}:\
 ${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
IFMT/nbproject/project.xml
 
 org.netbeans.modules.java.j2seproject
 
 
 IFMT
 
 
 
 
 
 
 
 
IFMT/src/Exercicios.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
 * 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 joao
 */
public class Exercicios {
 public static void main(String[] args) {
 int vet[] = new int[25], cont = 0, lin = 0, col = 0, pos, chave;
 int[][] mat = new int[5][5];
 double[][] notas = new double[5][5];
 String linha = "";
 InputStreamReader isr = new InputStreamReader(System.in);
 BufferedReader br = new BufferedReader(isr);
 try {
 // Preenchendo o Vetor
 while (cont < 25) {
 System.out.println("Digite o valor n<" + cont + ">");
 linha = br.readLine();
 vet[cont++] = Integer.parseInt(linha);
 }
 //Lendo a chave a ser buscada no vetor
 System.out.println("Digite o numero a buscar no vetor:");
 linha = br.readLine();
 chave = Integer.parseInt(linha);
 pos = buscaExaustiva(vet, chave, cont);
 // Preenchendo a Matriz
 for (int i = 0; i < 5; i++) {
 for (int j = 0; j < 5; j++) {
 System.out.println("Digite o valor da Linha<" + i + "> /Col:<" + j + ">");
 linha = br.readLine();
 mat[i][j] = Integer.parseInt(linha);
 }
 }
 //Preenchendo Notas
 for (int i = 0; i < 5; i++) {
 for (int j = 0; j < 5; j++) {
 System.out.println("Digite o valor da Nota[" + j + "] do Aluno<" + i + ">");
 linha = br.readLine();
 notas[i][j] = Double.parseDouble(linha);
 }
 }
 System.out.println("O Maior elemento do vetor e:[" + maior(vet, cont) + "]");
 System.out.println("O Menor elemento do vetor e:[" + menor(vet, cont) + "]");
 System.out.println("A Soma dos elementos do vetor e:[" + soma(vet, cont) + "]");
 System.out.println("A Media dos elementos do vetor e:[" + media(vet, cont) + "]");
 System.out.println("O elemento [" + chave + "] encontra-se na posicao[" + pos + "]do vetor");
 matMaiorelemento(mat, lin, col);
 System.out.println("Maior elemento Matriz [" + mat[lin][col] + "] etsa na Linha[" + lin + "] coluna[" + col + "]");
 for (int i = 0; i < 5; i++) {
 System.out.println("A Media do Aluno n.<" + i + "> é:[" + mediaNota(notas[i], 5) + "]");
 }
 } catch (IOException | NumberFormatException e) {
 }
 }
 public static void matMaiorelemento(int[][] mat, int lin, int col) {
 int maior = mat[0][0];
 lin = 0;
 col = 0;
 for (int i = 0; i < 5; i++) {
 for (int j = 0; j < 5; j++) {
 if (mat[i][j] > maior) {
 lin = i;
 col = j;
 maior = mat[i][j];
 }
 }
 }
 }
 public static int maior(int[] vet, int tl) {
 int maior = vet[0];
 for (int i = 0; i < tl; i++) {
 maior = (vet[i] > maior) ? vet[i] : maior;
 }
 return maior;
 }
 public
static int menor(int[] vet, int tl) {
 int menor = vet[0];
 for (int i = 0; i < tl; i++) {
 menor = (vet[i] < menor) ? vet[i] : menor;
 }
 return menor;
 }
 public static int soma(int[] vet, int tl) {
 int soma = 0;
 for (int i = 0; i < tl; i++) {
 soma += vet[i];
 }
 return soma;
 }
 public static double media(int[] vet, int tl) {
 double media = 0;
 int i;
 for (i = 0; i < tl; i++) {
 media += vet[i];
 }
 return (media / i);
 }
 public static double mediaNota(double[] vet, int tl) {
 double media = 0;
 int i;
 for (i = 0; i < tl; i++) {
 media += vet[i];
 }
 return (media / i);
 }
 public static int buscaExaustiva(int[] vet, int chave, int tl) {
 int pos = 0;
 while (pos < tl && vet[pos] != chave) {
 pos++;
 }
 return (vet[pos] == chave) ? pos : -1;
 }
}

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Continue navegando