简体   繁体   中英

error in caling a method. (java)

in this program I want to show pascals triangle using users' input. but there is an error. what is the error in calling pascaltriangle method? (the error says, multiple markers at this line). How can I fix this? thanks in advance.

import java.util.Scanner;

public class pascal{
    static int userinput=0;
static Scanner myscanner= new Scanner(System.in);

public static void main(String[] args) {
    prln("give pascals' triangles length:");
    int userInput=myscanner.nextInt();
    if(userInput>0){
            pascalstriangle(userinput);
    }
}


    static void pascalstriangle(int a){
        int pascal[][]= new int[a][a];
        for(int c=0;c<a;c++){
            pascal[0][c]=1;
            pascal[c][0]=1;
        }
        for(int row=1;row<a;row++){
            for(int column=1;column<(a-row);column++){
                pascal[row][column]=pascal[row-1][column]+pascal[row][column-1];
            }
        }
        for(int row=1;row<a;row++){
            for(int column=1;column<(a-row);column++){
                pr(pascal[row][column]+"\t");
            }
            prln("\n");
        }

    }




public static void pr(Object cop)   {
    System.out.print(cop);
}
public static void prln(Object c6op)    {
    System.out.println(c6op);
}

}

Here I found some problems in your code.

  1. Instead of

     pascal[row][column]=pascal[row-1][column]+pascal[row[column-1]; 

use

pascal[row][column]=pascal[row-1][column]+pascal[row][column-1];
  1. check main() method closing braces.
  2. check class closing braces.

Not only these. some more problems are there..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM