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 3 of 3

Thread: Hey guys I need some help

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hey guys I need some help



    import java.util.Scanner;
    public class Matrix {
     
     
    public static void main(String[] args) {
     
    Scanner scan = new Scanner(System.in);
     
    double[][] matrix = new double[3][4];
    System.out.println("Enter a " + matrix.length + "-by-" + matrix[0].length + " matrix row by row:"  );
     
    for (int row = 0; row < matrix.length; row++) {
    for (int column = 0; column < matrix[row].length; column++) {
     
     
    matrix[row][column] = scan.nextDouble();
    System.out.print(matrix[row][column] + " ");
    }
    System.out.println();
    }                        
    for (int i = 0; i < 4; i++) {
    System.out.println("Sum of column " + i + " is " + sumColumn(matrix, i));
    }
    }
     
    public static double sumColumn(double[][] m, int columnIndex) {
    double sum = 0;
    for (int i = 0; i < m.length; i++) {
    sum += m[i][columnIndex];
    }
    return sum;
    }
    }

    what did I do wrong?
    Last edited by kenamine; October 25th, 2012 at 09:49 PM.


  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hey guys I need some help

    I get

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hey guys I need some help

    nvm I got it now!
     import java.util.Scanner;
    public class Matrix {
     
     
    public static void main(String[] args) {
     
    Scanner input = new Scanner(System.in);
     
    double[][] matrix = new double[3][4];
    System.out.println("Enter a " + matrix.length + "-by-" + matrix[0].length + " matrix row by row:"  );
     
    for (int row = 0; row < matrix.length; row++) {
    for (int column = 0; column < matrix[row].length; column++) {
     
     
    matrix[row][column] = input.nextDouble();
     
       }
    }                        
    for (int i = 0; i < 4; i++) {
    System.out.println("Sum of column " + i + " is " + sumColumn(matrix, i));
    }
    }
     
    public static double sumColumn(double[][] m, int columnIndex) {
    double sum = 0;
    for (int i = 0; i < m.length; i++) {
    sum += m[i][columnIndex];
    }
    return sum;
    }
    }

Similar Threads

  1. Hey guys:)))
    By mimka15 in forum Member Introductions
    Replies: 0
    Last Post: April 26th, 2012, 01:27 PM
  2. Hey guys! :D
    By goingforcoffee in forum Member Introductions
    Replies: 0
    Last Post: April 4th, 2012, 11:01 AM
  3. Hey guys
    By StarKannon in forum Member Introductions
    Replies: 2
    Last Post: February 2nd, 2011, 04:58 AM
  4. hey guys....
    By prince joseph in forum Member Introductions
    Replies: 2
    Last Post: March 27th, 2010, 11:15 PM