Results 1 to 6 of 6

Thread: java

  1. #1
    noranata is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default java

    Java Code:
    import java.util.Scanner;
    
    
    
    public class Average
    {
    	private int [] data;
    	private double mean;
    
    	public Average () // this is the constructor
    	{
    		data = new int [5];
    		Scanner keyboard = new Scanner (System.in);
    		
    		for (int i = 0; i < data.length; i++)
                    {
    			System.out.print("Enter score number " + (i+1) + ":  ");
    			data[i] = keyboard.nextInt();
                    	           
                    
                    }
                             
    public void selectionSort();
        
    		int maxIndex;
    		int maxValue;
                    {	
    		for (int startScan = 0; startScan < data.length-1; startScan++)
    		{
    			maxIndex = startScan;
    			maxValue = data[startScan];
    			for (int index = startScan + 1; index < data.length; index++)
    			{
    				if (data[index] > maxValue)
    				{
    					maxValue = data[index];
    					maxIndex = index;
    				}
    			}
    			data[maxIndex] = data[startScan];
    			data[startScan] = maxValue;
                            {           
                    
                            }	
                
              /**
         *
         */
         
        public final void calculateMean()
    	{
    		//Caluculate Mean of the data;
    		// using defined class fields data and mean
    	}
    	
        @Override
    	public String toString()
    	{
    		String output;
    		output ="The test scores in descending order are \n";
    		
    		for (int i = 0; i < data.length; i++)
    		{
    			output = output + data[i] + "     ";
    		}
    		output = output + "\nThe average is " + mean;
    		return output;
    	}
        
    
    public class AverageDriver{
        
    
    	   /**
                *
                * @param args
                */
               public void main(String [] args)
            {
            	Average testScore = new Average();
    		System.out.println(testScore);
    	}
    
    }   
        
    }
    please can someone help me check why it is giving me illegal start of expression

  2. #2
    angstrem is offline Member
    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Default Re: java

    Past here the exception text.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: java

    If that code dump is stored in one file: you can't have more than one public class/interface definition in a single file.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: java

    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: java

    you close the constructor first after you start the function definition..

    And then you create the functions after closing one function.

    So you made the mistake on closing the functions and constructor.

    So you correctly close your functions and constructor.
    Regards
    Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: java

    Quote Originally Posted by tamilarasi View Post
    you close the constructor first after you start the function definition..

    And then you create the functions after closing one function.

    So you made the mistake on closing the functions and constructor.

    So you correctly close your functions and constructor.
    Java doesn't have functions. Java has methods.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •