Advertisement
Alan_Cesar

Maior_Vetor_JAVA

Mar 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //Aluno : Alan Cesar
  2. //Projeto: Unicarioca
  3. //Data : 22/03/2017
  4.  
  5. import javax.swing.JOptionPane;
  6.  
  7. public class Vetor {
  8.  
  9. private int vet[];
  10.  
  11.  
  12. public Vetor(int _n){
  13.  
  14. this.vet=new int[_n];
  15.  
  16. }
  17. public void setVet(){
  18. try{
  19.  
  20.  
  21. int n=this.vet.length;
  22.  
  23. for(int c=0;c<n;c++){
  24.  
  25.  
  26. String aS=JOptionPane.showInputDialog("Digite o Array : "+c);
  27. int a=Integer.parseInt(aS);
  28. this.vet[c]=a;
  29.  
  30. }
  31.  
  32. for(int c=0;c<n;c++){
  33.  
  34.  
  35. String sX="Vetor : "+this.vet[c];
  36. JOptionPane.showMessageDialog(null,sX);
  37.  
  38.  
  39. } }catch(Exception e){
  40.  
  41.  
  42. System.out.println("Erro : "+e.getMessage());
  43.  
  44. }
  45. }
  46.  
  47. public void maiorVet(){
  48.  
  49. int n=this.vet.length;
  50. int maior=0;
  51. int c;
  52.  
  53. for(c=0;c<n;c++){
  54.  
  55. if(this.vet[c]>maior){
  56.  
  57. maior=this.vet[c];
  58. }
  59. }
  60. String vM="Maior vetor : "+maior;
  61. JOptionPane.showMessageDialog(null,vM);
  62. }
  63.  
  64. public static void main(String[] args) {
  65.  
  66. Vetor obj=new Vetor(3);
  67. obj.setVet();
  68. obj.maiorVet();
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement