4 Replies - 474 Views - Last Post: 03 May 2013 - 07:15 PM Rate Topic: -----

#1 cakcukz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-April 13

problem sum of the column matrix of the smallest

Posted 30 April 2013 - 08:30 PM

I have a problem with the sum of random numbers from the smallest to the largest, but the result without changing the order of the numbers.
example: 9 1 3 7 4 result will be 29 1 4 15 8
please its support
thankz

like this, but this the result of this sum is not in accordance with the order of the matrix colomnya, but from the smallest number to the largest

public  class matriks{
    @SuppressWarnings("empty-statement")
    public static void main (String[] args) {
    int rows = 4;
    int cols = 5;
    int[][] matrix = {
  { 5, 9, 8, 10, 1 },
  { 9, 3, 10, 1, 8 },
  { 9, 4, 5, 8, 6 },
  { 4, 8, 8, 7, 2 }
};
    System.out.println();
    
     for (int i=0; i<rows; i++)
  { for (int j=0;j<cols;j++) {
      if (i==0){
          matrix[i][j]=0;
         System.out.print(matrix[i][j]+" "); 
      }
      else{
          System.out.print( matrix[i][j]+" ");
      }
  } 
  System.out.println();
  }
     System.out.println();
     
 int[] array1 = {  matrix[1][0], matrix[2][0], matrix [3][0] };
     int min1=100;
     int baris1;
     
     for(int i=0; i<array1.length; i++){
        
         if(array1[i]<min1){
             min1=array1[i];
             baris1=i;
//             System.out.println("Baris :"+baris1);
         }
     }
     System.out.println("Nilai terkecilnya M1 adalah "+min1);
    
     int temp;
//     System.out.print("Nilai urutan job1=0 ");
     
     for(int i=1; i<array1.length; i++){
         for(int j=array1.length-1; j>=i; j--){
             if(array1[j]<array1[j-1]){
                 temp=array1[j];
                 array1[j]=array1[j-1];
                 array1[j-1]=temp;
             }
              
         }   
         }
     int a = (+min1);
     for (int i=0;i<array1.length;i++) {
          // System.out.print( +array1[i]);
           
            if(+array1[i]>+min1){
            a = (+array1[i])+(+a);
}
            System.out.println(+a);
           
     }
     for (int i=0;i<array1.length;i++) {
     }
     System.out.println();


Is This A Good Question/Topic? 0
  • +

Replies To: problem sum of the column matrix of the smallest

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: problem sum of the column matrix of the smallest

Posted 01 May 2013 - 02:51 AM

I don't think anyone understands what you're asking. This:

"example: 9 1 3 7 4 result will be 29 1 4 15 8"

is completely mysterious.
Was This Post Helpful? 0
  • +
  • -

#3 cakcukz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-April 13

Re: problem sum of the column matrix of the smallest

Posted 03 May 2013 - 12:07 PM

View PostGregBrannon, on 01 May 2013 - 02:51 AM, said:

I don't think anyone understands what you're asking. This:

"example: 9 1 3 7 4 result will be 29 1 4 15 8"

is completely mysterious.


sequence was derived from the sum of numbers from the smallest to the largest, but it does not change the composition of numbers initially
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: problem sum of the column matrix of the smallest

Posted 03 May 2013 - 03:25 PM

Showing the derivation of that result would have been helpful, but you can keep it as mysterious as you like. If you'd like help, give an explanation we can understand. The sequence

9, 1, 3, 7, 4

does not appear in the matrix you posted, and summing them to get 29 is impossible.

What you've described sounds like ordering the numbers from smallest to largest and then adding them somehow. I don't get the "not change the composition" part.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,913
  • Joined: 06-March 08

Re: problem sum of the column matrix of the smallest

Posted 03 May 2013 - 07:15 PM

View Postcakcukz, on 30 April 2013 - 11:30 PM, said:

I have a problem with the sum of random numbers from the smallest to the largest, but the result without changing the order of the numbers.
example: 9 1 3 7 4 result will be 29 1 4 15 8


Explain how you go from 9 1 3 7 4 to 29 1 4 15 8
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1