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...
By slk on the 9th of Feb 2010 11:42:26 PM
Download |
Raw |
Embed |
Report
import java.util.Scanner;
public class ProcurasVector {
static int procuraIdx(int vect[], int num) {
for(int i=0; i<vect.length; i++) {
if(vect[i]==num)
return i;
}
return -1;
}
static int procuraMaior(int vect[]) {
int maior=vect[0];
for(int i=0; i<vect.length; i++) {
if(vect[i]>=maior)
maior=vect[i];
}
return maior;
}
static int procuraMenor(int vect[]) {
int menor=vect[0];
for(int i=0; i<vect.length; i++) {
if(vect[i]<=menor)
menor=vect[i];
}
return menor;
}
static void preencheArray(int vect[]) {
Scanner buffer
= new Scanner
(System.
in);
for(int i=0; i<vect.length; i++) {
vect[i]=buffer.nextInt();
}
}
public static void main
(String[] args
) {
int array[] = new int[5];
int num;
Scanner buffer
= new Scanner
(System.
in);
preencheArray(array);
System.
out.
println("-----------------------------");
System.
out.
print("Procurar: ");
num = buffer.nextInt();
System.
out.
println("-----------------------------");
System.
out.
print("'"+num
+"' na posicao: "+ procuraIdx
(array, num
)+"\n");
System.
out.
println("-----------------------------");
System.
out.
println("Maior = "+ procuraMaior
(array
));
System.
out.
println("Menor = "+ procuraMenor
(array
));
}
}
Submit a correction or amendment below.
Make A New Post