import java.util.*;
 public class Try{
 	private int [] arr;
	private final int MAX=10;
		Scanner scan=new Scanner(System.in);

	public Try(){
 	arr =new int[MAX];
	public void accept(){
		for(int i=0;i<arr.length;i++) 
	public int smallest(){
		int smallest=0;
		for (int i=0;i<arr.length;i++) 
		return smallest;
	public int largest(){
			int largest=0;
		for(int i=0;i<arr.length;i++)
			return largest;	
	public int sum(){
		int sum=0;
	for(int i=0;i<arr.length;i++)
	return sum;
	public static void main(String [] args){
	int arr[ ]= {1,5,6,4,78,9,56,2,3,50};
/*public int fibonacci(){}
  can u teach me how to do the fibonacci

Can someone help me how put a main in this program...

5 Years
Discussion Span
Last Post by javaAddict

First of all, the methods for smallest, largest are wrong. You initialize at both cases with zero.
For example you set smallest=0, but what if the user enters only positive numbers, at the accept method?:
Then the smallest 0 will always be smaller than all the elements of the array and the method will return 0 instead of the right value 1

The same goes with the other method. You need to initialize the smallest/largest variable with the first element of the array.

As far as Fibonacci, try to find the formula for fibonacci numbers and implement it. I think that each fibonacci number is the sum of the previous 2 so you will need to have variable with the first 2 values and then use them to calculate the third and then recursively the fourth from the previous 2 and so on.
Have a method with argument n that returns the nth fibonacci number. If n=1 or n=2 just return the fixed values, else calculate based on the formula


Collections.sort(arr); //acs
Collections.sort(arr, Collections.reverseOrder()); //decs

The idea is for someone to learn as an exercise how to sort an array or how to find the max/min number. Not to just call a method and let it do the work for you. The idea is to learn how to think and implement solutions for your problem. Not all problems can be solved by methods provided by java

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.