Plz help me with the below code | Selenium Forum
M
Posted on 03/01/2017
To find largest number in code---if i make first element in array as biggest one ,code is not working ..plz let me know


public class Largestnum{
public static void main(String[] args){
int[] x ={25,21,7,8,20};
int biggest=0;
for(int i=1;i<x.length;i++)
{
//System.out.println(biggest);
if(x[i]>biggest)
biggest=x[i];
}
System.out.println("Biggest number is"+biggest);

}


}

M
Replied on 03/01/2017

[quote:kn6pvwj4]for(int i=1;i<x.length;i++)[/quote:kn6pvwj4]

you're starting i=1; don't do that start[color=#FF0000:kn6pvwj4] i=0;[/color:kn6pvwj4]



this should work
[code:kn6pvwj4]public class Largestnum{
public static void main(String[] args){
int[] x ={25,21,7,8,20};
int biggest=0;
for(int i=0;i<x.length;i++)
{
//System.out.println(biggest);
if(x[i]>biggest)
biggest=x[i];
}
System.out.println("Biggest number is"+biggest);

}


}
[/code:kn6pvwj4]


M
Replied on 03/01/2017

[quote="deepuhc@gmail.com":3523udkc]To find largest number in code---if i make first element in array as biggest one ,code is not working ..plz let me know


public class Largestnum{
public static void main(String[] args){
int[] x ={25,21,7,8,20};
int biggest=0;
for(int i=1;i<x.length;i++)
{
//System.out.println(biggest);
if(x[i]>biggest)
biggest=x[i];
}
System.out.println("Biggest number is"+biggest);

}


}[/quote:3523udkc]


M
Replied on 03/01/2017

Worked out.THANK YOU.