wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

sudha siva
Ranch Hand

Joined: Sep 18, 2001
Posts: 30
public class Array1{
int[] Ki[]=new int[9][];
public int guessWhat( int arr[] ){
int x= 0;
for( int i = 0; i < arr.length; i++ ){
x = x < arr[i] ? arr[i] : x;
System.out.println(x);
}
return x;
}
public static void main(String args[]){
Array1 a=new Array1();
System.out.println(a.guessWhat(new int[9]));
}
}
/*
a) Returns the index of the highest element in the array
b) Returns true/false if there are any elements that repeat in the array
c) Returns how many even numbers are in the array
d) Returns the highest element in the array
e) Returns the number of question marks in the array
20. Which of the following are legal declarations of a two-dimensional array of integers?

Can anyone tell me which one is the correct answer (with detailed explanations)for the above code.
Thanks
sudha

Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Originally posted by sudha siva:
public class Array1{
int[] Ki[]=new int[9][];
public int guessWhat( int arr[] ){
int x= 0;
for( int i = 0; i < arr.length; i++ ){
x = x < arr[i] ? arr[i] : x;
System.out.println(x);
}
return x;
}
public static void main(String args[]){
Array1 a=new Array1();
System.out.println(a.guessWhat(new int[9]));
}
}
/*
a) Returns the index of the highest element in the array
b) Returns true/false if there are any elements that repeat in the array
c) Returns how many even numbers are in the array
d) Returns the highest element in the array
e) Returns the number of question marks in the array
20. Which of the following are legal declarations of a two-dimensional array of integers?

Can anyone tell me which one is the correct answer (with detailed explanations)for the above code.
Thanks
sudha


Hi sudha...
This code works but it prints all zero's. So i am sorry i am unable to comprehend the answer choices correctly to pick. However I believe the question should be little bit clearer. It must provide additional information like the input arrays contains positive values or something like that to pick the choice d
Ranchers any comments?
Ragu
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Answer is d

Explanation:

  • At Line 7 gussWhat() is called.By passing the reference[/I] of int array of 9 objects.NOT INITIALIZED!THEREFORE EVERY ELEMENT OF INT ARRAY IS 0
  • At Line 3, local variable x is compared with every element of array arr[].Rememebr this array holds the reference of the array pased at Line 7.i.e [I]new int[9]
  • At Line 3 x is compared in such a way with arr[] elements that the greatest of either(i.e x or arr[]) will be assinged to x.
  • Since all the elements of arr[] are 0 therefore condition at Line 3 false & x is assinged to x.
  • Finnaly at Line 5 x is returned, which holds 0.


  • Hope this helps.Any frther quesry is Wellcome
    Bye.
    Viki
    ------------------
    Count the flowers of ur garden,NOT the leafs which falls away!
    [This message has been edited by Vikrama Sanjeeva (edited November 20, 2001).]

    [This message has been edited by Vikrama Sanjeeva (edited November 20, 2001).]


Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays
 
Similar Threads
How to do �shallow copy� and �deep copy�?
creating a list of subsets from N elements
MindQ
Operators
Very Interesting Question