Why functions are called methods in java?

This question already has an answer here: Difference between a method and a function 33 answers It's not in Java, it's an OOP name. In sort, it defines part of the behavior of an instance of an object, not a general operation. Every language has it's own syntax to differentiate from others. As for your question Functions existence is independent. Methods do not as they ar

为什么函数在java中被称为方法?

这个问题在这里已经有了答案: 方法和函数之间的区别33答案 它不是Java,它是一个OOP名称。 在排序中,它定义了对象实例的一部分行为,而不是一般操作。 每种语言都有自己的语法来区分他人。 至于你的问题 函数的存在是独立的。 方法并不像它们在类中创建的那样。 为什么函数在java中被称为方法? 方法在一个对象上。 函数独立于对象。 对于Java,只有方法。 对于C,只有函数。 对于C ++来说,这取决于

Are functions only in non

This question already has an answer here: Difference between a method and a function 33 answers Are functions found only in non-object-oriented languages? No. There are object-oriented languages that have functions. C#, for example, is an object-oriented language but it has anonymous functions. What are the named procedures which are members of a type typically called in object-oriented

职能只在非

这个问题在这里已经有了答案: 方法和函数之间的区别33答案 函数是否仅在非面向对象的语言中找到? 没有。有一些面向对象的语言具有功能。 例如,C#是一种面向对象的语言,但它具有匿名功能。 什么是通常在像Java或C#这样的面向对象语言中调用的类型成员的已命名过程? 通常他们被正确地称为方法,尽管这种语言不同。 在Java或C#中,我会说“方法”。 例如,在Visual Basic中,根据函数和子例程是否返回一个值,

Java's methods vs. functions

This question already has an answer here: Difference between a method and a function 33 answers In my opinion this figure http://www.jot.fm/issues/issue_2008_03/article4/images/figure2.gif from http://www.jot.fm/issues/issue_2008_03/article4/ helps understanding one of the main differences between OO and procedural programming. Basically the idea is that Procedural programming provides o

Java的方法与功能

这个问题在这里已经有了答案: 方法和函数之间的区别33答案 在我看来这个图http://www.jot.fm/issues/issue_2008_03/article4/images/figure2.gif 来自http://www.jot.fm/issues/issue_2008_03/article4/有助于理解OO和程序编程之间的主要区别之一。 基本上这个想法就是这样 程序编程只提供一个维度来将计算单位与名称相关联。 这里,过程调用或名称直接映射到过程实现。 在图中,调用m1别无选择,只能调用过程m1的唯

Should private helper methods be static if they can be static

Let's say I have a class designed to be instantiated. I have several private "helper" methods inside the class that do not require access to any of the class members, and operate solely on their arguments, returning a result. public class Example { private Something member; public double compute() { double total = 0; total += computeOne(member); total +

如果私人帮手方法是静态的,那么它们应该是静态的

假设我有一个旨在实例化的类。 我在类中有几个私有的“helper”方法,它们不需要访问任何类成员,并且只对它们的参数进行操作,并返回结果。 public class Example { private Something member; public double compute() { double total = 0; total += computeOne(member); total += computeMore(member); return total; } private double computeOne(Something arg) { ... }

Solve Number Puzzle with C and Java

This question is translated into English by me from another forum, I found it interesting and then just write a Java solution. And found there's some heap size problem when dealing with large number like 10000000. And I would like to seek some really smart solution compared with my own. Original Post is in Chinese. And I kind of revised it a little based on my understanding to make it cle

用C和Java解决数字拼图

这个问题被我从另一个论坛翻译成英文,我发现它很有趣,然后只是写一个Java解决方案。 并且发现在处理像10000000这样的大数量时存在一些堆大小问题。我想与我自己相比寻找一些非常聪明的解决方案。 原帖是用中文。 根据我的理解,我稍微修改了一下,以便更清楚。 http://zhidao.baidu.com/question/1637660984282265740.html?sort=6&old=1#here 以下是难题: 10000 rows of numbers; 1 row: 2,4,6,8...2K(2K<=1000

Sudoku solving algorithm with back

I'm looking to implement a very simple algorithm that uses brute-force back-tracking to solve Sudoku grids. The problem I'm facing is that in my implementation I included two instance variables for a Sudoku class called row and col , which correspond to the row and column of an empty cell in a two dimensional array that represents the Sudoku grid. When my solve() method executes it fir

数独求解算法

我期待实现一个非常简单的算法,它使用蛮力反向跟踪来解决数独网格。 我面临的问题是,在我的实现中,我包含了一个名为row和col的Sudoku类的两个实例变量,它们对应于表示Sudoku网格的二维数组中的空单元格的行和列。 当我的solve()方法执行时,首先检查是否没有空单元,在这种情况下,拼图已经完成。 否则,该方法将空单元格的行和列分配给包含网格的Sudoku对象的实例变量row和col 。 之后,for循环通过方法调用isSafe(int

Run normal on Eclipse but get RESULT 0 in SPOJ website and get some error

I'm new bie I have a small java program. This is my code import java.util.Scanner; class Mark { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.println("press mark: "); float a = sc.nextFloat(); if ( a <= 100 && a >= 90 ) System.out.println("A"); if ( a >= 85 && a

在Eclipse上运行正常但在SPOJ网站中获得RESULT 0并出现一些错误

我是新人 我有一个小型的java程序。 这是我的代码 import java.util.Scanner; class Mark { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.println("press mark: "); float a = sc.nextFloat(); if ( a <= 100 && a >= 90 ) System.out.println("A"); if ( a >= 85 && a < 90 )

Unexpected behavior of Scanner

This question already has an answer here: Close a Scanner linked to System.in 5 answers The reason is quite simple, closing the 1st scanner object closes internally too the input stream which is actually being used by the second scanner your options are: use only one scanner or close those when you are sure all of them are not required anymore..

Scanner的意外行为

这个问题在这里已经有了答案: 关闭与System.in链接的扫描仪5个答案 原因很简单,关闭第一个扫描器对象也会关闭第二个扫描器实际使用的输入流 您的选择是:只使用一台扫描仪或在您确定所有这些扫描仪都不再需要时关闭这些扫描仪。

Scanner within scanner error

When trying to scan a text file and then scan each individual line in the text file to create an object I get the error below. Any idea on how I can fix this? Error: java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1371) at MyZoo.readDataFromFile(MyZoo.java:111) while(scanner.hasNextLine()){ lineOfInput = scanner.nextL

扫描仪内的扫描仪错误

当试图扫描一个文本文件,然后扫描文本文件中的每个单独的行来创建一个对象时,我会得到下面的错误。 任何想法如何我可以解决这个问题? 错误: java.util.Scanner.throw上的java.util.NoSuchElementException (MyException.java:111) while(scanner.hasNextLine()){ lineOfInput = scanner.nextLine(); if(lineOfInput.startsWith("#")){ } else { String animalType, species, name; Scanne

Java: scanner compile errors

i'm currently working on a simple battleship-game. i'm using the Java-scanner to get coordinates from the user. if I run this code in eclipse i get no errors, everything is just fine. but if I'm running the code in another compiler (eg http://www.compilejava.net/) i get this error: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.S

Java:扫描器编译错误

我目前正在研究一个简单的战列舰游戏。 我使用Java扫描器从用户获取坐标。 如果我在eclipse中运行这段代码,我不会遇到任何错误,一切都很好。 但如果我在另一个编译器中运行代码(例如http://www.compilejava.net/),则会出现此错误: 线程“main”中的异常java.util.NoSuchElementException:在SchiffeVersenken.main的SchiffeVersenken.attack(SchiffeVersenken.java:57)处的java.util.Scanner.nextLine(Scanner.java: