Results 1 to 3 of 3

Thread: Help?!

  1. #1
    Hounted is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Help?!

    Please, why it doesn't work?
    Java Code:
    package lista.vetores;
    import java.util.*;
    
    public class Ex2 {
    public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    float vet  [] = new float[15];
    int i = 0;
    float maior = 0;
    float menor = 1000000;
    while(i<15)
    {System.out.println("input number":)
     vet [i] = sc.nextFloat();
     i++;
    if (Arrays.binarySearch(vet, i)>M)
     {M = vet[i];}
     else {
     if (Arrays.binarySearch(vet, i)<m)
     {m = vet[i];}
            }
     }
    System.out.println(" most of 15:"+M+" "+"smallest of 15:"+m);
     
    }    
    }
    Last edited by Hounted; 04-07-2012 at 03:07 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help?!

    Some suggestions to help you get better help here:
    • Please use a thread title that tells us something about the underlying nature of your problem. "help" tells us nothing we don't already know -- you wouldn't be posting a question here if you didn't need help. Think of the thread title as being similar to the headline of a newspaper article -- a single small sentence that summarizes all.
    • Please explain just how your code is not working? Does it compile? run? give bad results?
    • If you get any error messages, please post their full text.
    • Please use [code] [/code] tags around your code so it retains its format and is readable.


    Good luck and welcome here.

  3. #3
    Hounted is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: Help?!

    sorry
    if i put him to work he will ask for the 15 values and results to an error
    when i remove those parts with if and else the code work... but i need him to work with then...
    at the end it show
    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 15
    	at lista.vetores.Ex2.main(Ex2.java:26)
    Java Result: 1
    Thanks for the welcome
    Last edited by Hounted; 04-07-2012 at 03:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •