Homework Help Question & Answers

I must implement a class to calculate n-th row of Pascal's Triangle (in Java). I need...

I must implement a class to calculate n-th row of Pascal's Triangle (in Java).

I need to create a static method that takes an argument "n" and returns the n'th line of pascal's triangle.

the main method, which will call the class, is already done and the class is set up. Please build this without modifying the main method and without modifying exactly what the static method returns.

public class Main {

    public static void main(String[] args) {

        int n = args.length == 1 ? Integer.parseInt(args[0]) : 1;

        for (int i = 1; i <= n; ++i) {
            int[] arr = Pascal.triangle(i);
            System.out.print((i < 10 ? " " : "") + i + ": ");
            for (int j : arr) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

class Pascal {

    public static int[] triangle(int n) {

        return new int[]{0};
    }
}
0 0
Answer

This Homework Help Question: "I must implement a class to calculate n-th row of Pascal's Triangle (in Java). I need..." No answers yet.

Be the First!

Request Answer

Request answer!

We need 10 more requests to produce the answer to this homework help question. Share with your friends to get the answer faster!

0 /10 have requested the answer to this homework help question.

Request! (Login Required) Share with friends


Once 10 people have made a request, the answer to this question will be available in 1-2 days.
All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
I must implement a class to calculate n-th row of Pascal's Triangle (in Java). I need...
Your Answer: Your Name: What's your source?
Similar Homework Help Questions
  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • the code needs to be modifed. require a output for the code Java Program to Implement...

    the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • Help with a question in Java: What is the output from the following program? public class...

    Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }

  • I had to create a triangle class and implement that class in java.

    I'm new to java and my professor throws us into the dark with these projects. I had to create a parameterless constructor and a parameterized constructor for atriangle. All the methods in the class are the only methods allowed in it. I tried my best with this project but I can't get it to work. After I enter the coordinatesof the vertices for the triangle, it automatically makes all the coordinates of the vertices (0,0) which then makes everything else...

  • Java Im doing a binary search on an array and need to allow as many queries...

    Java Im doing a binary search on an array and need to allow as many queries as possible and cannot figure out how to. The output should read something like this. Enter a number. 3 3 is a prime number. Enter another number. 4 4 is not a prime number. Enter another number. 8 Current file not large enough for 8. Enter another number. -1 Bye. My code so far looks like this. public static void main(String[] args)    {...

  • Introduction to java programming 8th edition by Y. Daniel liang

    show the output of the following program when invoked using1.java Test I Have a Dream2. java Test "1 2 3"3.java Test4.java Test "*"5.java test *public class test {public static void main(String[] args) {System.out.println("number of Strings is " + args.length);for (int i = 0; i < args.length; i++)System.out.println(args[i]);}}

  • /** this is my code, and I want to invoke the method, doubleArraySize() in main method....

    /** this is my code, and I want to invoke the method, doubleArraySize() in main method. and I need to display some result in cmd or terminal. also, I have classes such as Average and RandomN needed for piping(pipe). please help me and thank you. **/ import java.util.Scanner; public class StdDev { static double[] arr; static int N; public static void main(String[] args) { if(args.length==0){ arr= new double[N]; Scanner input = new Scanner(System.in); int i=0; while(input.hasNextDouble()){ arr[i] = i++; }...

  • I need to make this code access the main method I suppose, but I don't know...

    I need to make this code access the main method I suppose, but I don't know how to make that happen... Help please! QUESTION: Write a method called switchEmUp that accepts two integer arrays as parameters and switches the contents of the arrays. Make sure that you have code which considers if the two arrays are different sizes. Instructor comment: This will work since you never go back to the main method, but if you did, it wouldn't print out...

  • QUESTION 21 What exception will the following program raise? class Main f public static void main(Stringl...

    QUESTION 21 What exception will the following program raise? class Main f public static void main(Stringl args) try System.out.print Hello"1/0); catch ( e) f codes are not provided** DataFormatException InputMismatchException ArithmeticException DividedByZeroException QUESTION 19 Suppose we had the following method header: public void someMethod (int someNumber) Which of the following is an overloaded version of this method? public void someMethod (int someNumber, int anotherNumber) O public int someMethod (int anotherNumber) O public void someMethod (int anotherNumber) public void anotherMethod (int...

Free Homework App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.