📄 sequence.txt
字号:
// Program to generate the Syracuse sequence for a
// number entered by the user
import javax.swing.JOptionPane;
public class Sequence
{
public static void syracuse()
{
int length = 0; // Initially no numbers generated
String str = JOptionPane.showInputDialog(
"Enter starting number?");
int num = Integer.parseInt(str);
while ((num != 1) && (length < 10)) // Stop if sequence finishes or
{ // reaches ten terms
if (num % 2 == 0) // num is even
num = num / 2;
else // num is odd
num = 3 * num + 1;
System.out.println("Next number is " + num);
length++;
}
}
public static void main(String[] args)
{
syracuse();
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -