• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

clear the doubt please

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)what will be the output?
char[] c = new char[100];

c[50]

2) why the output is 24 what happend to other ...
class S {


public static void main(String[] args) {
int[] dayhigh = { 24, 23, 24, 25, 25, 23,32 };

for(int i=0;i<dayhigh.length;i++)
{

System.out.println(dayhigh[0]);
}

}

}


24

24

24

24

24

24

24
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why the output is 24 what happend to other ...
class S
{
public static void main(String[] args) {
int[] dayhigh = { 24, 23, 24, 25, 25, 23,32 };
for(int i=0;i<dayhigh.length;i++)
{
System.out.println(dayhigh[0]);
}
}
}

Hi Friend,

Length variable will give the Length of the Variable. In this case it is 7.
You are printing the value of daylight[0]. so it is printing value 24, 6th times.

If you give the Statement as
System.out.println(dayhigh[i]);
it will print all the 7 values.
[ April 27, 2005: Message edited by: deepak bhalotia ]
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am sorry i ovelooked the details
i am closing the topic
 
deepu Bhalotia
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)what will be the output?
char[] c = new char[100];

c[50]

Array gets initialized to their default values.Character's default value is space. So when you print c[50], nothing is displayed on the screen.

With Regards,
Deepak
 
reply
    Bookmark Topic Watch Topic
  • New Topic