• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clear the doubt please

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • 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
 
deepu Bhalotia
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic