public double computePayment(double loanAmt,
double rate,
double futureValue,
int numPeriods) {
double interest = rate / 100.0;
double partial1 = Math.pow((1 + interest),
- numPeriods);
double denominator = (1 - partial1) / interest;
double answer = (-loanAmt / denominator)
- ((futureValue * partial1) / denominator);
return answer;
}
我是Java的初学者,对参数有疑问。究竟是什么?我认为它们是方法中使用的变量,但现在我看到其他变量如interest和partial1在方法中使用。这些变量是从参数变量派生出来的,但参数是什么?
提前致谢。
答案 0 :(得分:1)
括号中的参数列表 - 以逗号分隔的输入参数列表,以其数据类型开头,括在括号中,()。如果没有参数,则必须使用空括号。
您可以查看Defining Methods
了解详情。
答案 1 :(得分:1)
rate
,futureValue
,numPeriods
和interest
是参数,而partial1
,Calling "D:\Migration_Workspace\Jboss\Jboss-8\wildfly-8.2.0.Final\bin\standalone.conf.bat"
Setting JAVA property to "C:\Program Files\Java\jdk1.8.0_11\bin\java"
===============================================================================
JBoss Bootstrap Environment
JBOSS_HOME: "D:\Migration_Workspace\Jboss\Jboss-8\wildfly-8.2.0.Final"
JAVA: "C:\Program Files\Java\jdk1.8.0_11\bin\java"
JAVA_OPTS: "-Dprogram.name=standalone.bat -Xms64M -Xmx512M -XX:MaxPermSize=256M -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pk
gs=org.jboss.byteman"
===============================================================================
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
17:12:34,600 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.3.Final
17:13:20,638 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.2.Final
17:13:20,746 INFO [org.jboss.as] (MSC service thread 1-3) JBAS015899: WildFly 8.2.0.Final "Tweek" starting
17:14:28,350 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (manage
ment-http)
17:15:06,125 INFO [org.xnio] (MSC service thread 1-4) XNIO version 3.3.0.Final
17:15:06,161 INFO [org.xnio.nio] (MSC service thread 1-4) XNIO NIO Implementation Version 3.3.0.Final
17:15:06,210 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
17:15:06,212 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 32) JBAS010280: Activating Infinispan subsystem.
17:15:06,206 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 40) JBAS011800: Activating Naming Subsystem
17:15:06,238 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 31) WFLYIO001: Worker 'default' has auto-configured to 4 core t
hreads with 32 task threads based on your 2 available processors
17:15:06,242 INFO [org.jboss.as.security] (ServerService Thread Pool -- 45) JBAS013171: Activating Security Subsystem
17:15:06,209 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 46) JBAS010153: Node identifier property is set to the default value. P
lease make sure it is unique.
17:15:06,290 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 38) JBAS012615: Activated the following JSF Implementations: [main]
17:15:06,326 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017502: Undertow 1.1.0.Final starting
17:15:06,348 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017502: Undertow 1.1.0.Final starting
17:15:06,435 INFO [org.jboss.remoting] (MSC service thread 1-4) JBoss Remoting version 4.0.6.Final
17:15:06,781 INFO [org.jboss.as.naming] (MSC service thread 1-4) JBAS011802: Starting Naming Service
17:15:06,807 INFO [org.jboss.as.mail.extension] (MSC service thread 1-3) JBAS015400: Bound mail session [java:jboss/mail/Default]
17:15:06,828 INFO [org.jboss.as.connector.logging] (MSC service thread 1-3) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.9.Final)
17:15:06,842 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant d
river class org.h2.Driver (version 1.3)
17:15:06,858 INFO [org.jboss.as.security] (MSC service thread 1-3) JBAS013170: Current PicketBox version=4.0.21.Final
17:15:07,045 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010417: Started Driver service with driver-name = h
2
17:15:07,457 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017527: Creating file handler for path D:\Migrati
on_Workspace\Jboss\Jboss-8\wildfly-8.2.0.Final/welcome-content
17:15:07,485 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017525: Started server default-server.
17:15:07,502 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017531: Host default-host starting
17:15:07,601 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-4) JBAS015012: Started FileSystemDeploymentService for di
rectory D:\Migration_Workspace\Jboss\Jboss-8\wildfly-8.2.0.Final\standalone\deployments
17:15:07,606 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "EJBJPAExample.jar" (runtim
e-name: "EJBJPAExample.jar")
17:15:07,751 INFO [org.jboss.as.jpa] (MSC service thread 1-3) JBAS011401: Read persistence.xml for ejbjpa
17:15:07,772 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."EJBJPAEx
ample.jar".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."EJBJPAExample.jar".PARSE: JBAS018733: Failed to pr
ocess phase PARSE of deployment "EJBJPAExample.jar"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.2.0.Final
.jar:8.2.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1
.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Fina
l]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_11]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_11]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_11]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: ParseError at [row,col]:[3,6]
Message: found: CHARACTERS, expected START_ELEMENT or END_ELEMENT
at org.jboss.as.connector.deployers.ds.processors.DsXmlDeploymentParsingProcessor.deploy(DsXmlDeploymentParsingProcessor.java:100)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.2.0.Final
.jar:8.2.0.Final]
... 5 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,6]
Message: found: CHARACTERS, expected START_ELEMENT or END_ELEMENT
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.nextTag(XMLStreamReaderImpl.java:1254) [rt.jar:1.8.0_11]
at org.jboss.jca.common.metadata.ds.v10.DsParser.parseDataSources(DsParser.java:161)
at org.jboss.jca.common.metadata.ds.v10.DsParser.parse(DsParser.java:124)
at org.jboss.jca.common.metadata.ds.v10.DsParser.parse(DsParser.java:87)
at org.jboss.as.connector.deployers.ds.processors.DsXmlDeploymentParsingProcessor.deploy(DsXmlDeploymentParsingProcessor.java:89)
... 6 more
17:15:08,237 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017519: Undertow HTTP listener default listening on /127.0
.0.1:8280
17:15:08,617 INFO [org.jboss.ws.common.management] (MSC service thread 1-4) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.3
.2.Final
17:15:08,899 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:jboss/datas
ources/ExampleDS]
17:15:09,345 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - addres
s: ([("deployment" => "EJBJPAExample.jar")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"EJBJPAExamp
le.jar\".PARSE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"EJBJPAExample.jar\".PARSE: JBAS018733: Failed t
o process phase PARSE of deployment \"EJBJPAExample.jar\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: ParseError at [row,col]:[3,6]
Message: found: CHARACTERS, expected START_ELEMENT or END_ELEMENT
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,6]
Message: found: CHARACTERS, expected START_ELEMENT or END_ELEMENT"}}
17:15:09,453 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "EJBJPAExample.jar" (runtime-name : "EJBJPA
Example.jar")
17:15:09,457 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.deployment.unit."EJBJPAExample.jar".PARSE: org.jboss.msc.service.StartExce
ption in service jboss.deployment.unit."EJBJPAExample.jar".PARSE: JBAS018733: Failed to process phase PARSE of deployment "EJBJPAExample.ja
r"
17:15:09,613 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:10190/manage
ment
17:15:09,616 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:10190
17:15:09,627 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: WildFly 8.2.0.Final "Tweek" started (with errors) in 155428ms - Star
ted 187 of 238 services (1 services failed or missing dependencies, 82 services are lazy, passive or on-demand)
17:15:09,728 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment EJBJPAExample.jar (runtime-name
: EJBJPAExample.jar) in 9ms
17:15:09,868 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "EJBJPAExample.jar" (runtime-name: "EJBJPAE
xample.jar")
17:15:09,879 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.deployment.unit."EJBJPAExample.jar".PARSE
等等局部变量。参数作为方法调用的一部分从外部传递,局部变量供内部使用。
答案 2 :(得分:1)
方法参数基本上只是将值(或对象的引用)传递给方法的可能性。如果您有一个添加两个值的方法,则需要使用这些值。它们通过此方法的参数传递。因此,如果您的方法需要一些其他信息,您可以通过参数传递此信息。
答案 3 :(得分:1)
它不仅仅是关于Java而是通用编程语言概念,下面提到的变量是方法/函数参数,它也是方法签名的一部分,而partial1
和interest
是声明的局部变量在函数内声明,因此仅限于函数范围内。
double loanAmt,
double rate,
double futureValue,
int numPeriods
因此,在调用函数computePayment
时,您将不得不提供那些不起作用的参数/您的程序将无法编译,因为这些参数是函数的依赖项。
答案 4 :(得分:0)
术语参数(有时称为形式参数)通常用于表示函数定义中的变量,参数出现在过程定义中。
参数是过程的固有属性,包含在其定义中。例如,在许多语言中,将两个提供的整数相加并计算总和的过程需要两个参数,每个整数一个。
函数test
有两个参数,名为parm1
和parm2
。它添加传递给参数的值,并将结果返回给子例程的调用者。
int test(int parm1, int parm2)
{
return parm1 + parm2;
}