Results 1 to 6 of 6
  1. #1
    highschool is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default need help with question(method & array)

    can any1 explain what the question want?
    it would be better if any of u guys would help me do lol

    1)
    write method that return if and onli if an integer array contains duplicate items. test this method in a program. include another method that reads a list of numbers,terminate by -999 into an array

    2) write method that return second largest vale-stored in an array of type int. write a main program that will read a list of member. detect weather there is any duplicate in the array and if there is non,find the second largest value stored in the array. you can make use of the function writen in (1)

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What have you done so far and where are you stuck?

  3. #3
    highschool is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    import java.util.Scanner;

    public class method
    {

    int [] array;
    int arraySize = 100;
    array = new int[100];
    int main(array)
    {
    int size;
    size = method+B();
    if(method_A(array,size));
    system.out.println("duplicate occur!!");
    else
    system.out.printlv("2nd largest %d",method_C);

    return 0;
    }

    bool method_A(int[]ary , int size)
    {
    int item = ary[0];
    bool found = true;
    for(int i = 1;i<size&&amp;found;i++)
    {
    if(ary[i] == item)
    found = false;
    else
    item = ary[i];
    }
    return found;
    }


    bool method_A(int[]ary , int size)
    {
    int item = ary[0];
    bool found = true;
    for(int i = 1;i<size&&amp;found;i++)
    {
    if(ary[i] == item)
    found = false;
    else
    item = ary[i];
    }
    return found;
    }

    int method_C(int[] ary,int size)
    {
    int largest = ary[0];
    int 2nd_largesr = ary [1];

    for(int i = 2;i<size;i++)
    {
    if(ary[i]>2nd_largest)
    {
    if(ary[i]>largest){
    2nd_largest=largest;
    largest=ary[i];
    }
    else
    {
    2nd_largest=ary[i];
    }
    }
    return 2nd_largest;
    }

    int method_B()
    {
    Scanner keyboard = new Scanner(System.in);

    int input,i=0;
    system.out.print(Enter the number");
    input = keyboard.nextInt();

    while(input!=-999)
    {
    array[i] = input;
    system.out.print("enter the number");
    input = keyboard.nextInt();
    i++;
    }
    return i;
    }


    this is wat i have done so far but i also duno wat is the problem anymore

  4. #4
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    what do you mean? is it giving a compilation error or a logical error?

  5. #5
    highschool is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    wat u mean by compilation error or logical?
    i onli got a rough idea about what the question
    i do this with a help of my frens
    i'm stil very new to jave

  6. #6
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    hi

    what i meant was did you try compiling the code? if you did , did it successfully compile or

    didnt you get the expected output from the code(logical error).

Similar Threads

  1. split method question
    By Chasingxsuns in forum New To Java
    Replies: 3
    Last Post: 11-19-2009, 07:19 PM
  2. method question
    By xplayerr in forum New To Java
    Replies: 7
    Last Post: 11-11-2009, 04:13 PM
  3. Learning - 2D array and method question.
    By Russo in forum New To Java
    Replies: 24
    Last Post: 09-15-2009, 08:16 AM
  4. Simple Method Question
    By Froz3n777 in forum New To Java
    Replies: 2
    Last Post: 02-13-2008, 02:39 AM
  5. Return question in a method.
    By MetalGear in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 04:45 AM

Posting Permissions

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