Results 1 to 6 of 6
- 02-10-2010, 09:51 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
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, 10:07 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What have you done so far and where are you stuck?
- 02-10-2010, 04:32 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
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&&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&&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, 04:48 PM #4
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
what do you mean? is it giving a compilation error or a logical error?
- 02-10-2010, 04:51 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
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, 05:06 PM #6
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
Similar Threads
-
split method question
By Chasingxsuns in forum New To JavaReplies: 3Last Post: 11-19-2009, 07:19 PM -
method question
By xplayerr in forum New To JavaReplies: 7Last Post: 11-11-2009, 04:13 PM -
Learning - 2D array and method question.
By Russo in forum New To JavaReplies: 24Last Post: 09-15-2009, 08:16 AM -
Simple Method Question
By Froz3n777 in forum New To JavaReplies: 2Last Post: 02-13-2008, 02:39 AM -
Return question in a method.
By MetalGear in forum New To JavaReplies: 1Last Post: 01-13-2008, 04:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks