Issue: I don't know how to print 10 integers in a row, add then onto a new line, and repeat this pattern until it fill out to 25 integers as displayed in the instructions Java Code: import java.util.Scanner; public class Hailstone { /* Type your code here. */ public int hailstone(int num) { int i=1; if (num == 1) { System.out.println("1"); return 1; } else { System.out.print(num + "\t"); if (num %2==0) return 1 + hailstone(num/2); else return 1 + hailstone(3*num +1); } } /* for (int i=0; i < 10; i++) { --> I need to print 10 integers in a row, follow by a new line until it reaches 25 integers as displayed in the instructios. I don't know where to put this for loop. */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Hailstone labObject = new Hailstone(); int num; num = scnr.nextInt(); labObject.hailstone(num); // Call hailstone() to print out the hailstone sequence. } }
Issue:
I don't know how to print 10 integers in a row, add then onto a new line, and repeat this pattern until it fill out to 25 integers as displayed in the instructions
Java Code:
import java.util.Scanner;
public class Hailstone {
/* Type your code here. */ public int hailstone(int num) {
int i=1;
if (num == 1) {
System.out.println("1");
return 1;
}
else {
System.out.print(num + "\t");
if (num %2==0)
return 1 + hailstone(num/2);
else
return 1 + hailstone(3*num +1);
}
}
/* for (int i=0; i < 10; i++) { --> I need to print 10 integers in a row, follow by a new line until it reaches 25 integers as
displayed in the instructios. I don't know where to put this for loop. */
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
Hailstone labObject = new Hailstone();
int num;
num = scnr.nextInt();
labObject.hailstone(num); // Call hailstone() to print out the hailstone sequence.
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images