Tuesday, December 23, 2014

Find Largest and Smallest Number in an Array in java class pro



Find Largest and Smallest Number in an Array

public class FindLargestSmallestNumber
{
public static void main(String[] args)
{
int numbers[] = new int[]{32,43,53,54,32,65,63,98,43,23};
int smallest = numbers[0];
int largetst = numbers[0];
for(int i=1; i< numbers.length; i++)
{
if(numbers[i] > largetst)
largetst = numbers[i];
else if (numbers[i] < smallest)
smallest = numbers[i];
}
System.out.println("Largest Number is : " + largetst);
System.out.println("Smallest Number is : " + smallest);
   }
}

Hello World

public class HelloWorldExample
{
public static void main(String args[])
{
Use System.out.println() to print on console.
System.out.println("Hello World !");
  }
}


Java Class

public class JavaClassExample
{
Syntax of defining memebers of the java class is,
type ;
private String name;
Syntax of defining methods of the java class is,
methodName()
{
}
public void setName(String n)
{
name = n;
}
public String getName()
{
return name;
}
public static void main(String args[])
{
Syntax of java object creation is,
object-name = new ;
JavaClassExample javaClassExample = new JavaClassExample();
javaClassExample.setName("Visitor");
System.out.println("Hello " + javaClassExample.getName());      
  }
}

No comments:

Post a Comment