简体   繁体   English

我的Java hello-world程序正确吗?

[英]Is my Java hello-world program correct?

I just started a Java Programming class and received my first assignment. 我刚刚开始Java编程课程,并收到了我的第一份作业。 I am tasked with the following 我的任务如下

  1. Construct a simple flowchart that describes simple logic flow through a program (this is easy, I have done this) 构造一个简单的流程图,描述通过程序的简单逻辑流程(这很简单,我已经做到了)
  2. Translate said flowchart into pseudo code (I know this is easy, but still working on it.) 将所述流程图转换为伪代码(我知道这很简单,但仍在进行。)
  3. Create a simple module based off that pseudo code, which accepts a parameter and returns a value. 基于该伪代码创建一个简单的模块,该模块接受一个参数并返回一个值。

"Technically" speaking, is the Hello World! 从技术上讲,就是Hello World! initial program doing what #3 is requesting? 初始程序正在执行#3的要求? I suppose I am just a little confused on terminology as to what a "parameter" is and what a "value" is in Java. 我想我对Java中的“参数”是什么以及“值”是什么在术语上有些困惑。

Does anyone have an example they could point me to? 有谁能给我指出一个榜样? Or is this the same as saying something like 还是说像这样的话

Mymethods test1 = new MyMethods();
int aVal = test1.total();
System.out.println("Method result = " + aVal);

(pulled this from the book) (从书中拉出)

Just slightly confused. 只是有些困惑。 Any help to explain this to my like I'm 5 would be incredibly appreciated. 像我5岁时向我解释这个问题的任何帮助将非常感激。

If your question is what parameters are first see this : what functions are ?<\\b> If I say you 如果您的问题是首先要使用哪些参数,请参见:什么是功能?<\\ b>如果我说您

Raise your hand ! 举起你的手!

That could be said as you.raiseHand() 可以说是you.raiseHand()

If I say you 如果我说你

Raise your hand by 120° 将您的手举起120°

It could be you.raiseHand(120) 可能是you.raiseHand(120)

Now that 120 is the value that is passed as argumemt. 现在,120是作为argumemt传递的值。

How values go?<\\b> 值如何变化?<\\ b>

Consider this function 考虑这个功能

public boolean raiseHand(int deg){
useEnergy(10);
if(canRaise(deg))return true;
return false; }

Your passed 120 goes as deg. 您通过的120度。

Your program: 您的程序:

Mymethods test1 = new MyMethods();
int aVal = test1.total();

System.out.println("Method result = " + aVal); System.out.println(“ Method result =” + aVal);

In line 1 you are creating an instance (object) of class Mymethods . 在第1行中,您将创建类Mymethods的实例(对象)。 Its like you are creating a substance that has access to Mymethods. 就像您正在创建可以访问Mymethods的物质一样。 Rather read more about class. 而是阅读有关课程的更多信息。 I guess it wasnt a good eg. 我想那不是一个好例子。

In line 2 you are creating a new variable and storing result of function call. 在第2行中,您将创建一个新变量并存储函数调用的结果。 As first eg of raising hand you are storing if you have succesfully raised hand or not. 首先举手,如果您成功举手,则要存储。

In last you are printing it 最后,您正在打印它

it says you should accept a parameter and return a value. 它说您应该接受一个参数并返回一个值。 That means that your method should accept a parameter for example: 这意味着您的方法应接受一个参数,例如:

public int addTen(int initialValue){
     return initialValue+10;
}
int myMethod(int a, int b)
{
   int value = a+b;
    return value;
}

Code Details 代码详细信息

In the above example a and b are parameters, and v is value... 在上面的示例中,a和b是参数,v是值...

anything that is returned is called value. 返回的任何东西都称为值。
anything that is passed (eg a and b) is called parameter. 传递的任何内容(例如a和b)都称为参数。
Your book example 您的书籍范例

Mymethods test1 = new MyMethods();
int aVal = test1.total();
System.outprintln("Method result = " + aVal);

Explanation in line 3 "Method result =" +aVal" is the parameter and printed output will b the value :) 第3行中的解释 “方法结果=“ + aVal”是参数,并且打印输出将b值:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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