Recent Posts
None | 10 sec ago
None | 17 sec ago
PHP | 19 sec ago
None | 29 sec ago
MySQL | 59 sec ago
Bash | 1 min ago
None | 1 min ago
None | 2 min ago
None | 2 min ago
None | 2 min ago
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By slk on the 9th of Feb 2010 11:42:26 PM Download | Raw | Embed | Report
  1. import java.util.Scanner;
  2.  
  3. public class ProcurasVector {
  4.  
  5.         static int procuraIdx(int vect[], int num) {
  6.                 for(int i=0; i<vect.length; i++) {
  7.                         if(vect[i]==num)
  8.                                 return i;
  9.                 }
  10.                 return -1;
  11.         }
  12.        
  13.         static int procuraMaior(int vect[]) {
  14.                 int maior=vect[0];
  15.                 for(int i=0; i<vect.length; i++) {
  16.                         if(vect[i]>=maior)
  17.                                 maior=vect[i];
  18.                 }
  19.                 return maior;
  20.         }
  21.  
  22.         static int procuraMenor(int vect[]) {
  23.                 int menor=vect[0];
  24.                 for(int i=0; i<vect.length; i++) {
  25.                         if(vect[i]<=menor)
  26.                                 menor=vect[i];
  27.                 }
  28.                 return menor;
  29.         }
  30.        
  31.         static void preencheArray(int vect[]) {
  32.                 Scanner buffer = new Scanner(System.in);
  33.                 for(int i=0; i<vect.length; i++) {
  34.                         System.out.print("Valor: ");
  35.                         vect[i]=buffer.nextInt();
  36.                 }
  37.         }
  38.                
  39.         public static void main(String[] args) {
  40.                 int array[] = new int[5];
  41.                 int num;
  42.                 Scanner buffer = new Scanner(System.in);
  43.                 preencheArray(array);
  44.                 System.out.println("-----------------------------");
  45.                 System.out.print("Procurar: ");
  46.                 num = buffer.nextInt();
  47.                 System.out.println("-----------------------------");
  48.                 System.out.print("'"+num+"' na posicao: "+ procuraIdx(array, num)+"\n");
  49.                 System.out.println("-----------------------------");
  50.                 System.out.println("Maior = "+ procuraMaior(array));
  51.                 System.out.println("Menor = "+ procuraMenor(array));
  52.         }
  53.  
  54. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: