# need help with question(method & array)

• 02-10-2010, 10:51 AM
highschool
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)
• 02-10-2010, 11:07 AM
r035198x
What have you done so far and where are you stuck?
• 02-10-2010, 05:32 PM
highschool
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
• 02-10-2010, 05:48 PM
[RaIdEn]
what do you mean? is it giving a compilation error or a logical error?
• 02-10-2010, 05:51 PM
highschool
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
• 02-10-2010, 06:06 PM
[RaIdEn]
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).