So I have the 3N+1 problem already, I am just not sure where I need to insert, an if statement to adjust the ranges it accepts.
https://gyazo.com/8970fee9207de0239d37f9cc3622e345
import java.util.Scanner;
public class Lab3Problem1StewartSpencer {
public static void main(String[] args) {
/* Declare variables:*/
int start = -1;
String seq;
/* Create scanner: /
Scanner stdin = new Scanner(System.in);
/ Get user input that is range-checked.*/
// Loop until the user gives a positive integer:
do {
// Prompt user for an integer:
System.out.println("Please enter a even positive integer:");
// Get input:
start = stdin.nextInt();
} while (start < 1); // Check that the input is positive and even.
//} while (start < 1 || start % 2!= 0 ); // OLD: Check that the input is positive and even.
// Begin the string report for out sequence:
seq = start + ", ";
/* Main work loop.*/
// Loop until the sequence reaches a value <= 1.
while (start > 1) {
if (start % 2 == 0){ // Is it even?
start = start /2;
} else { // Is sequence value odd?
start = 3 start +1;
}
//System.out.println(start);
// Create an updated report string:
if (start == 1) {
seq = seq + start + ", ";
}
else{
seq = seq + start + ", ";
}
}
/ Show results. */
System.out.println("Your sequence is:" + seq);
}
}
https://gyazo.com/8970fee9207de0239d37f9cc3622e345
import java.util.Scanner;
public class Lab3Problem1StewartSpencer {
public static void main(String[] args) {
/* Declare variables:*/
int start = -1;
String seq;
/* Create scanner: /
Scanner stdin = new Scanner(System.in);
/ Get user input that is range-checked.*/
// Loop until the user gives a positive integer:
do {
// Prompt user for an integer:
System.out.println("Please enter a even positive integer:");
// Get input:
start = stdin.nextInt();
} while (start < 1); // Check that the input is positive and even.
//} while (start < 1 || start % 2!= 0 ); // OLD: Check that the input is positive and even.
// Begin the string report for out sequence:
seq = start + ", ";
/* Main work loop.*/
// Loop until the sequence reaches a value <= 1.
while (start > 1) {
if (start % 2 == 0){ // Is it even?
start = start /2;
} else { // Is sequence value odd?
start = 3 start +1;
}
//System.out.println(start);
// Create an updated report string:
if (start == 1) {
seq = seq + start + ", ";
}
else{
seq = seq + start + ", ";
}
}
/ Show results. */
System.out.println("Your sequence is:" + seq);
}
}
![[Image: UJB3B5t.png]](https://i.imgur.com/UJB3B5t.png)


