I have less than a day to understand and learn evrything there is to know about arrays and to be able to know what the output for a code on arrays will give..

I was hoping someone will be able to suggest any good sites etc.. from which i can learn from

Less than a day? :-) Ok. I've been doing serious software engineering for 30+ years and am still learning about this subject (and others). Let's start with what you DO know, and then move to what you NEED to know!

i have a few questions which im working on to understand.. so if any comments on them could be helpfull.

import javax.swing.*;

public class Main {

   public static void main(String[] args) {
       String strMark = "" ;

        int[] mark = new int[10];
        int size = mark.length;
        int failed=0;

        for ( int i = 0; i < size; i++ )
        {
            strMark = JOptionPane.showInputDialog( "Enter mark:" ) ;
            mark[i] = Integer.parseInt( strMark ) ;
            if (mark[i] < 40) failed++;
        }

        System.out.println("Failures = " + failed);
        for ( int i = 0; i < mark.length; i++ )
        {
            System.out.println(mark[i]);
        }
    }
}





QUESTION 5

import java.util.*;

public class Main {



    public static void main(String[] args) {

        int[] numbers = new int[6];
        int temp=0;

        Scanner input = new Scanner(System.in);

        for (int i = 0; i< numbers.length; i++)
        {
            numbers[i] = input.nextInt();
        }

        temp = numbers[0];// store the firts element

        //copy element from right to left
        for(int i = 0; i < numbers.length-1; i++)
        {
            numbers[i] = numbers[i+1];
        }

        //copy the original first element into the last

        numbers[numbers.length-1]=temp;

        for (int i = 0; i< numbers.length; i++)
        {
            System.out.println(numbers[i] + " ");
        }
    }

}


QUESTION 6
import java.util.* ;

public class Main {

    public static void main(String[] args) {
        double[] numbers = new double[20];
        double temp=0;
        int swap1, swap2;

        Scanner input = new Scanner(System.in);

        for (int i = 0; i< numbers.length; i++)
        {
            numbers[i] = input.nextDouble();
        }

        System.out.print("Imput first index: ");
        swap1 = input.nextInt();
        System.out.print("Imput second index: ");
        swap2 = input.nextInt();

        temp = numbers[swap1];
        numbers[swap1]=numbers[swap2];
        numbers[swap2]=temp;

        //output new array
        for (int i = 0; i< numbers.length; i++)
        {
            System.out.print(numbers[i] + " ");
        }

    }
    }


QUESTION 7

import java.util.*;

public class Main {

    //some global variables

    static double[] numbers = new double[6];

    public static void main(String[] args) {
        int swap1, swap2;
        Scanner input = new Scanner(System.in);

        for (int i = 0; i< numbers.length; i++)
        {
            numbers[i] = input.nextDouble();
        }

        System.out.print("Imput first index: ");
        swap1 = input.nextInt();
        System.out.print("Imput second index: ");
        swap2 = input.nextInt();

        swap(swap1, swap2);

        //output ne atrray
        for (int i = 0; i< numbers.length; i++)
        {
            System.out.print(numbers[i] + " ");
        }

    }

    static void swap(int i, int j)
    {
        double temp;
        temp = numbers[i];
        numbers[i]=numbers[j];
        numbers[j]=temp;
    }

}


QUESTION 8

import java.util.*;

public class Main {

    //some global variables

    static double[] numbers = new double[6];

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
         int swap1, swap2;
         System.out.println("input array:");

        for (int i = 0; i< numbers.length; i++)
        {
            numbers[i] = input.nextDouble();
        }

        System.out.print("Imput first index: ");
        swap1 = input.nextInt();
        System.out.print("Imput second index: ");
        swap2 = input.nextInt();

        System.out.println ("in order? " + notInOrder(swap1, swap2));

        swap(swap1, swap2);

        //output ne atrray
        System.out.println("Array with swapped elements:");
        for (int i = 0; i< numbers.length; i++)
        {
            System.out.print(numbers[i] + " ");
        }

        System.out.println ("in order? " + notInOrder(swap1, swap2));

    }


    static void swap(int i, int j)
    {
        double temp;
        temp = numbers[i];
        numbers[i]=numbers[j];
        numbers[j]=temp;
    }

    static boolean notInOrder(int i , int j)
    {
        return numbers[i]>numbers[j];
    }

refer oracle site to understand Arrays.
And open src folder in your jdk installatiion path.Copy it into another location and try to understand java.lang package.It will clear most of your doubts.

Edited 3 Years Ago by IIM

I have tried to explain each statement of first example.HOpe it's clear.

import javax.swing.*;
    public class Main {//create a class Main
       public static void main(String[] args) {//main method
       String strMark = "" ;//Initialize String object with "" value
        int[] mark = new int[10]; //declare int array of 10 elements.Index starting from 0 to 9
        int size = mark.length;//get size of array.In our case it is 10
        int failed=0; // declare variable failed and assign zero
    for ( int i = 0; i < size; i++ ) //create a loop,statement below will be executed size times.
        {
 strMark = JOptionPane.showInputDialog( "Enter mark:" ) ;//Show input dialog box
mark[i] = Integer.parseInt( strMark ) ;//assign ith element value from the int value of dialog box
            if (mark[i] < 40) failed++;//If value of element is less than 40 increment fail by 1
        }
        System.out.println("Failures = " + failed); //Print number of failed
        for ( int i = 0; i < mark.length; i++ )//loop till the size of array
        {
            System.out.println(mark[i]);//print value of each elements of array
        }
    }
}

As for 5th question
This program is to rotate the array elements one place right

import java.util.*;//import classes inside java.util
public class Main {//class
    public static void main(String[] args) {//main method
        int[] numbers = new int[6]; //declare int array of 6 elements.Index starting from 0 to 5
        int temp=0;//declare variable temp and assign zero to it
        Scanner input = new Scanner(System.in);//create object of Scanner class to take input
        for (int i = 0; i< numbers.length; i++)//loop this size of array(in our case 6) times
        {
            numbers[i] = input.nextInt();//take int as input from user and assign it to ith array element
        }
        temp = numbers[0];// store the firts element//store first element value to temp
        //copy element from right to left
        for(int i = 0; i < numbers.length-1; i++)//loop this,size of array-1(5) times
        {
            numbers[i] = numbers[i+1];//copy ith+1 element value to ith element value.(eg if a[0]=5,a[1]=10,then after this a[1]=a[2]=10
        }
        //copy the original first element into the last
        numbers[numbers.length-1]=temp;//copy temp value to numbers[5]
        for (int i = 0; i< numbers.length; i++)//loop till the size of array
        {
            System.out.println(numbers[i] + " ");//print array element value
        }
    }
}

Edited 3 Years Ago by JamesCherrill: Fixed small error

less than a day to understand and learn evrything there is to know about arrays

no, you don't. no teacher would ask you this, since noone can get all of that within a day. the basics, sure, but not everything. there are advanced things to think of as well.

also, those "questions" you posted aren't questions. they are pieces of code that come without questions.

next to that, did you write that code? if it's code your teacher gave you, tell him there 's no such thing as "global variables" in Java. so, make sure you get the basics right, before passing to more complex structures.

As for 5th question
This program is to reverse the array elements

Are you quite sure it doesn't just rotate the elements right by 1 position?

[ edit: original post now updated as per IIM's comment]

Edited 3 Years Ago by JamesCherrill

This question has already been answered. Start a new discussion instead.