• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Array two dimension

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1public class GetArray {
2public static void main(String args[]) {
3float invt[][];
4float [] prct,grts[];
5float[][]sms,hms[];
6
7
8
9 }
10}

Which three statements should you insert on lines 6,7 and 8 to allow the class to compile without errors? (choose three)

A) invt = hms;
B) hms = prct;
C) invt = grts;
D) grts = new float[1];
E) hms = new float[2][5];
F) grts = new float[1][4];
G) invt = new float[4][2];
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Abdullateef, welcome to JavaRanch.

What do you think the answer to your question is, and why? You can easily try this out on your computer: enter the program with the different answers, try to compile it, see what works and what doesn't.
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abdullateef Abdulsalam

Answers to your problem are:

C) invt = grts;
F) grts = new float[1][4];
G) invt = new float[4][2];



because

prct is one dimensional Array Object type reference
invt, grts, sms are two dimensional Array Object type reference
hms is three Array Object type reference



Now, I think these statements will clear your doubts..
And you can easily make out why other options will cause compile-time errors..
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I want to rectify one thing about my reply..

I repeatedly wrote,

Array Object type reference



But actually they are refences to arrays of datatype float..
i.e. of the same primitive data ype..

Sorry for that..
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have tried to compile above program but for invt = grts;its showing compilation error .please give me the reason why?
[ June 22, 2007: Message edited by: Divya Gehlot ]
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have tried to compile above program but for invt = grts;its showing compilation error .please give me the reason why?



Because,



invt is a 2D array and grts[] is an 1D array. Thats why the incompatability and compiler-error!
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

invt is a 2D array and grts[] is an 1D array



How come grts[] is one dimensional..
And if it's show what would you say about dimension of hms..???
 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Then what would be the possible answers of the above given program? Could you please tell me and why?
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answers to the problem are:

C) invt = grts;
F) grts = new float[1][4];
G) invt = new float[4][2];



Compile time errors, U are getting because of not initializing the arrays before Using..

Try this code snippet:

public class GetArray {
public static void main(String args[]) {
float invt[][];
float [] prct,grts[];
float[][]sms,hms[];
invt = new float[2][3];
grts = new float[2][3];
invt = grts;

}
}



It compiles perfec[tly..
 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya its working fine. Thanks alot.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Abdullateef Abdulsalam",

Please Quote Your Sources.

Thanks,
Henry
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic