所以我为Collatz序列编写了代码,但我希望能够识别并打印出序列中出现的最大数字。这是我的代码:
import java.util.Scanner;
public class CollatzSequence {
public static void main(String[]args) {
Scanner keyboard = new Scanner(System.in);
int n,ts = 0;
System.out.print("This is the Lothar Collatz Sequnce. Please enter the starting number.\n>");
n = keyboard.nextInt();
do {
if (n % 2 == 0) {
n = n / 2;
System.out.println(n);
}
else {
n = n*3 + 1;
System.out.println(n);
}
ts++;
}
while (n != 1);
System.out.println("Terminated after "+ts+" steps.");
}
}
答案 0 :(得分:2)
创建一个名为max
的变量。最初将其设置为n
。在每个步骤中,检查n > max
是否为max
,如果是,请将n
设置为public function report(Exception $exception)
{
parent::report($exception);
Mail::send('emails.errorreport', ['e' => $exception], function($message)
{
$message->to('email@email.com')->subject('Report error');
});
}
。