Skip to content

Instantly share code, notes, and snippets.

@gmfc
Last active December 18, 2015 07:09
Show Gist options
  • Select an option

  • Save gmfc/5744662 to your computer and use it in GitHub Desktop.

Select an option

Save gmfc/5744662 to your computer and use it in GitHub Desktop.
estudo.java
import javax.swing.*;
public class juncao {
public static void main(String [] args){
int[] vetA;
int[] vetB;
int[] vetC;
int tamVetor = -1;
do{
tamVetor = entrInt("Entre com o tamanho do vetor A");
}while(tamVetor<=0);
vetA = new int[tamVetor];
tamVetor = 0;
do{
tamVetor = entrInt("Entre com o tamanho do vetor B");
}while(tamVetor<=0);
vetB = new int[tamVetor];
msg("Entre com os valores do vetor A");
preencheVetor(vetA);
msg("Entre com os valores do vetor B");
preencheVetor(vetB);
msg("Juntando vetor A e vetor B em vetor C");
vetC = new int[vetA.length+vetB.length];
for(int i=0;i<vetC.length;i++){
if(i<vetA.length){
vetC[i]=vetA[i];
}else{
vetC[i]=vetB[i-vetA.length];
}
}
selSrt(vetC);
mostrVetor(vetC);
}//main
public static void msg(String msg){
JOptionPane.showMessageDialog(null, msg);
}//msg
public static void mostrVetor(int[] v){
for(int i=0;i<v.length;i++){
msg("Posição: "+i+"\nValor: "+v[i]+"\n");
}
}//motrVetor
public static void preencheVetor(int[] v){
for(int i=0;i<v.length;i++){
v[i] = entrInt("Entre com o valor da posição: "+i);
}
}//preencheVetor
public static int entrInt(String msg){
return Integer.parseInt(JOptionPane.showInputDialog(msg));
}//entrInt
public static void selSrt(int v[]){
int n = v.length;
for(int x=0; x<n; x++){
int i = x;
for(int y=x; y<n; y++){
if(v[i]<v[y]){
i = y;
}
}
int temp = v[x];
v[x] = v[i];
v[i] = temp;
}
}//selSrt
}//class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment