java中的伪代码?
如何将这样的内容转换为伪代码?比如说java中的伪代码?,java,pseudocode,Java,Pseudocode,如何将这样的内容转换为伪代码?比如说 String s = ""; myf = new Finch(); do { //Run the menu until quit or cancel is selected s = FinchMenu(); //menu 1 if (s.equals("Back and forward")) RunAccelerationTest(s); } 它的伪代码是
String s = "";
myf = new Finch();
do
{
//Run the menu until quit or cancel is selected
s = FinchMenu();
//menu 1
if (s.equals("Back and forward")) RunAccelerationTest(s);
}
它的伪代码是这样的吗
String s = "";
对我来说,这似乎是错误的
需要帮忙吗?谢谢伪代码只是一个非特定于语言的人类可读演练,介绍了您正在尝试执行的任何操作
您可以将
设置s写入“”
,甚至使s成为空字符串
或任何其他描述这一步骤的内容。我认为伪代码没有预定义的语法。只需遵循两条规则:
- 它应该是通俗易懂的英语,带有通用的编程结构
- 它应该是通用的,而不是特定于任何语言
Set s to ""
一般来说(这完全是我使用伪代码的方式,而不是规则设置的任何东西),我使用伪代码来摆脱任何样板文件或语法正确的东西
例如,假设我有以下Java代码
Step 1: Initialize an empty string. (say str)
Step 2: Construct a new 'Finch' object.
Step 3: BEGIN LOOP
Fetch 'FinchMenu' from 'Finch' object.
assign 'FinchMenu' to 'str'
IF 'FinchMenu' is "Back and forward"
Call 'RunAccelerationTest' method with 'str' as argument.
END IF
END LOOP
我对伪代码的解释是
import java.io.*;
class FileRead
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
现在,这段代码可能对我以外的任何人都没有用处——但我知道我可以快速查看它,看看它是什么,并在必要时编写它。在会议上快速记笔记是很好的,如果我想写快速伪代码,就不必考虑异常处理。伪代码就是你所做的。读取伪代码标签wiki:伪代码是对计算机编程算法的一种简洁而非正式的高级描述。它表示代码,看起来可能类似于代码或代码构造,但它不是实际代码。它是代码或代码构造的一种表示形式)只要你写的东西是明确的并且类似于代码,它就是伪代码。请不要使用DataInputStream来阅读文本啊-太酷了,我没有意识到这与StringBuilder和StringBuffer是在同一个领域。谢谢你链接到你的博客,我会有一个gander:)这个DataInputStream每月有20篇文章堆垛溢出+fstream代码示例,因此它是不正确的。我很想找到这段代码的原始作者;)
main() {
FileInputStream fstream = new FileInputStream(fileLocation);
BufferedReader br = BufferedReader(.....fstream);
String str;
while(br.readline!=empty, str=br.readline) {
System.out(str);
}
}