5 Replies - 241 Views - Last Post: 30 November 2012 - 01:48 PM Rate Topic: -----

#1 dossfb0b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 12

array

Posted 29 November 2012 - 09:38 PM

I want to use an array that get from the use a number of students and there score, and calcultes the best score only and display it.I write the code but i do not know how to call the number from the array what is the code. I stoped here this is my code
package fa;
import java.util.Scanner;
public class Student1 {
    @SuppressWarnings("empty-statement")
    public static void main(String[] args){
       
        Scanner imput = new Scanner(System.in);
        double total;
        int numberOfStudent;
        int j=0;

        
        System.out.println("Enter the number of the student in the class: ");
        numberOfStudent = imput.nextInt();
       
        final int ARRAY_LENGTH =  numberOfStudent;
        int[] array = new int[ARRAY_LENGTH];
        
        
        for(int x = 1;x <= array.length; x++){
     
        System.out.printf("Enter The score of student%d :",x );

        array[j]=imput.nextInt();
        j++;
       
       }
      
   }
}





I do not know what to do and I am sorry about before

Is This A Good Question/Topic? 0
  • +

Replies To: array

#2 dossfb0b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 12

Re: array

Posted 29 November 2012 - 09:49 PM

04	    @SuppressWarnings("empty-statement")

I remove it so do not bother yourself
Was This Post Helpful? 0
  • +
  • -

#3 darek9576  Icon User is online

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,686
  • Joined: 13-March 10

Re: array

Posted 29 November 2012 - 09:51 PM

I read what you have written 10 times and i dont think i get it. If you want help, you need to know how to express your problems with assignment/homework/etc.

This might be what you are ooking for. Not sure.



import java.util.Arrays;
import java.util.Scanner;


public class Main 
{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter number of students: >>>  ");
        final int number = scanner.nextInt();
                
        int[] array = new int[number];
        
        for(int i=0; i < number; i++){
            System.out.printf("Enter the score for student: %d : >>> ", i);
            int score = scanner.nextInt();
            array[i] = score;
        }
        
        Arrays.sort(array);
        System.out.println("Max value is: " + array[array.length -1]);
    }
}



Was This Post Helpful? 0
  • +
  • -

#4 dossfb0b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 12

Re: array

Posted 30 November 2012 - 11:39 AM

thanks alot but what is the method to call the number from the array and see if they are above 90 and find the sum of it
Was This Post Helpful? 0
  • +
  • -

#5 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: array

Posted 30 November 2012 - 12:34 PM

What you describe is accomplished by iterating the array (visit each element in succession) and then using logic to determine other desired qualities, e.g. if an element is > 90, etc. The typical method for iterating an array is:
for ( int i = 0 ; i < array.length ; i++ )
{
    if array[i] > 90
    {
        // do what needs to be done
    }
}

Summing the elements of an array can be done simlarly, simply using a variable to which each element is added as the array is iterated.
Was This Post Helpful? 0
  • +
  • -

#6 dossfb0b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 12

Re: array

Posted 30 November 2012 - 01:48 PM

Thank you alot for help me it is good ansswer but with some chang
 if ((array[i] >= 90) && (array[i] <=100))

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1