Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用参数调用函数_Java_Function_Arguments - Fatal编程技术网

Java 用参数调用函数

Java 用参数调用函数,java,function,arguments,Java,Function,Arguments,我通常用Python编写代码,并且我已经开始学习Java,但是我在调用带有参数的方法时感到困惑。实际上,在Python中,您可以使用如下参数调用函数: my_function(argument) 这样创建之后: def my_function(argument): #Here I can use my argument like this print(argument) #if argument is a string 但是我还没有发现如何在Java中做同样的事情。事实上,我

我通常用Python编写代码,并且我已经开始学习Java,但是我在调用带有参数的方法时感到困惑。实际上,在Python中,您可以使用如下参数调用函数:

my_function(argument)
这样创建之后:

def my_function(argument):
    #Here I can use my argument like this
    print(argument) #if argument is a string
但是我还没有发现如何在Java中做同样的事情。事实上,我特别想这样做:

return new webPage() //this call my file named "webPage"
//But when I'm calling, I want to send the url of the
//web page and recover it in the other file

是的,你能做到,但差别不大 比如:

控制台计算器; 在这方面:

方法的调用类似于suma,b,你们现在应该知道方法的签名了,它的方法的调用类似于void-suma,double-b


注意:在方法a中,double b a和b是它的局部变量。

通过在返回的新网页中放置new,您希望实现什么?当您创建一个新对象时,您正在调用该类的构造函数,因此您需要创建一个带参数的构造函数。谢谢您的回答!但是我必须如何调用另一个Java文件中的函数呢?
public static void main(String[]args){
    Scanner scan = new Scanner(System.in);
    double a= scan.nextInt();
    double b= scan.nextInt();
    sum(a,b);
    sub(a,b)
    mul(a,b);
    div(a,b);
}
void sum(double a,double b){
    System.out.println("Sum :"+(a+b));
}
void sub(double a,double b){
    System.out.println("Sub :"+(a-b));
}void mul(double a,double b){
    System.out.println("Mul :"+(a*b));
}void div(double a,double b){
    System.out.println("Div :"+(a/b));
}