Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 17 of 17

Thread: two_dimentional_array + loop

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help !!!!two_dimentional_array + loop

    public class two_dimentional_array {
     
     
        public static void main(String[] args) {
    int gradearray [][] = new int[][]	{ { 60,61,70,98,60,69,69,69,67,69,55,69 },
    						  { 95,96,94,97,95,95,96,90,97,85,82,94 },
    						{ 50,54,51,57,50,55,52,55,56,53,65,62 },
    						{ 60,64,61,61,48,63,62,64,69,69,68,65 },
    						{ 60,64,61,64,50,65,55,68,57,58,61,98 },
    						{ 75,63,64,61,63,66,61,62,64,62,65,48 },
    					        { 61,63,62,58,60,98,59,61,65,55,67,65 },
    					        { 61,55,65,50,65,55,65,61,58,65,58,59 },
    						{ 65,61,94,61,65,64,62,65,55,58,59,61 },
    						{ 61,68,64,65,64,68,65,71,61,59,64,60 },
    					        { 60,60,64,60,63,61,60,62,65,60,69,60 },
    						{ 61,69,65,65,59,64,60,67,68,69,68,65 },
    						{ 61,64,65,63,66,65,61,65,59,61,64,60 },
    						{ 58,63,62,59,62,61,60,65,60,65,61,69 },
    						{ 61,62,65,67,61,66,67,64,67,61,67,68 },
    						{ 58,55,60,60,65,60,67,69,61,65,64,63 },
    						{ 60,69,68,68,67,60,60,69,59,60,58,58 },
    						{ 60,62,60,63,68,64,61,65,68,64,65,68 },
    						{ 64,62,65,64,59,60,58,61,65,59,58,62 },
    						{ 59,59,68,58,62,62,60,63,64,59,66,65 },
    						{ 69,62,65,65,68,64,59,63,64,62,55,55 },
    						{ 61,67,69,64,60,59,91,62,69,67,57,69 },
    						{ 58,68,65,66,60,61,62,61,62,65,69,69 },
    						{ 65,61,62,57,69,61,64,68,57,65,48,69 },
    						{ 62,58,91,59,60,61,65,57,67,62,69,67 },
    						{ 67,67,67,61,59,68,59,57,67,67,60,61 },
    					        { 67,60,62,58,65,55,67,55,60,61,63,69 },
    						{ 68,61,69,61,69,61,59,68,68,58,93,59 },
    						{ 62,67,68,60,62,58,61,63,61,69,69,61 },
    					        { 67,89,61,81,81,65,61,60,67,65,58,61 }};
     
    		int largest=0;
    		int smallest=9999;
    		int average=0;
    		int countermark=0;
     
     
    	for (int row = 0; row< gradearray.length; row++)
    	for (int column = 0; column< array1.length; row++)
     
    	System.out.print(""+ gradearray[row][column]);
     
    	{
    		System.out.println("");
    	}
    	{
    		for (int column = 0; column < gradearray[row].length; column++)
        	System.out.printf("%d", gradearray[row][column]);
     
        			if (gradearray > largest)
    			  		largest = gradearray;
     
    			  	if (gradearray < smallest)
    			  		smallest = gradearray;
     
    			  	if (gradearray[][] >70)
    			  		countermark= countermark +1;
    	}
     
    		System.out.printf("The largest number: %d\n", largest);
     
    		System.out.printf("The smallest number: %d\n", smallest);
     
    		System.out.printf("Average marks of : %d\n", average);
     
    		System.out.printf("more than 70: %d\n", countermark);
     
     
     
            // TODO code application logic here
        }
    }



    output:

    Highest Marks are:
    Student 1 Subject 4
    Student 5 Subject 12
    Student 7 Subject 6

    Coldest Days are:
    Student 4 Subject 5
    Student 6 Subject 12
    Student 24 Subject 11

    Average Mark of:
    Subject 1: 68
    Subject 2: 93
    Subject 3: 55


    25 student got marks higher than 70
    Last edited by w.kit; January 9th, 2012 at 10:05 AM.


  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    anyone can help me i got few error here.

  3. #3
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: two_dimentional_array + loop

    Quote Originally Posted by w.kit View Post
    anyone can help me i got few error here.
    What errors? Post them in their entirety, and for what its worth please read the link in my signature entitled 'Getting Help'

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    Quote Originally Posted by copeg View Post
    What errors? Post them in their entirety, and for what its worth please read the link in my signature entitled 'Getting Help'
    the error is all my number is stick together and can't separate row by row.
    plz advice.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,610
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: two_dimentional_array + loop

    error is all my number is stick together and can't separate row by row.
    Can you post some printout that shows what you mean?
    Add comments to the printout that shows what you want changed and what it should look like.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,610
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: two_dimentional_array + loop

    C:\Users\789456\Desktop\two_dimentional_array.java :69: error: '.class' expected
    Where are the indexes for the array?
    Last edited by Norm; January 9th, 2012 at 10:51 AM.

  7. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    Quote Originally Posted by Norm View Post
    What compiler are you using? I do not understand that error message.
    I don't remember seeing '.class' in an error message from the compiler.
    i using JCreator

  8. #8
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    there show that

    if (gradearray[][] >70)

    this symbol > got error

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,610
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: two_dimentional_array + loop

    The array reference needs index values.

  10. #10
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    Quote Originally Posted by Norm View Post
    The array reference needs index values.
    sorry i'm beginner in java.

    can u guide me what i should change?????

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,610
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: two_dimentional_array + loop

    Put the index values inside of the [][]
    Something like: anArray[ix][jx]
    You'll need to look at your logic to see what the correct indexes should be.

    Your code has empty [][] in: if (gradearray[][] >70)

  12. #12
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    Quote Originally Posted by Norm View Post
    Put the index values inside of the [][]
    Something like: anArray[ix][jx]
    You'll need to look at your logic to see what the correct indexes should be.

    Your code has empty [][] in: if (gradearray[][] >70)

    let do part by part
    i already changed my code

    // highest marks

    for (int rows = 0; row< student.length; row++)
    for (int column = 0; column<=11; column++)
    if (student[row][column]>=highest)
    highest= student[row][column];

    output:
    need to print out the highest subject and student.
    can teach me what should i continue??

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,610
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: two_dimentional_array + loop

    need to print out the highest subject and student.
    Can you explain your problem?

    How do you want to print the output?

  14. #14
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    Quote Originally Posted by Norm View Post
    Can you explain your problem?

    How do you want to print the output?
    this code is half only. need to continue to get to print the output but i stuck here.

  15. #15
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    Quote Originally Posted by w.kit View Post
    this code is half only. need to continue to get to print the output but i stuck here.
    output:

    Highest Marks are:
    Student 1 Subject 4
    Student 5 Subject 12
    Student 7 Subject 6

    Coldest Days are:
    Student 4 Subject 5
    Student 6 Subject 12
    Student 24 Subject 11

    Average Mark of:
    Subject 1: 68
    Subject 2: 93
    Subject 3: 55


    25 student got marks higher than 70

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,610
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: two_dimentional_array + loop

    but i stuck here.
    Please explain what your problem is.

    Can you find the value to print?

    Can you print the value that you found?

  17. #17
    Junior Member
    Join Date
    Jan 2012
    Location
    Mumbai
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: two_dimentional_array + loop

    Intresting...

Similar Threads

  1. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 07:57 PM
  2. For loop; Problems with my for loop
    By mingleth in forum Loops & Control Statements
    Replies: 5
    Last Post: November 16th, 2011, 06:24 PM
  3. [SOLVED] My while loop has run into an infinite loop...?
    By kari4848 in forum Loops & Control Statements
    Replies: 3
    Last Post: March 1st, 2011, 11:05 AM
  4. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 02:09 AM
  5. hi. i want to rewrite this do loop into a while loop.
    By etidd in forum Loops & Control Statements
    Replies: 3
    Last Post: January 26th, 2010, 04:27 PM