J 10 is an even number, so I take half: 5

O 5 is an odd number, so I make 3n + 1: 16

H 16 is an even number, so I take half: 8

N 8 is an even number, so I take half: 4

(TAB) 4 is an even number, so I take half: 2

D 2 is an even number, so I take half: 1

O The process took 6 steps to reach 1

However, with my code, all I get is:

J10 is an even number, so I take half: 5

J5 is an odd number, so I make 3n + 1: 16

J16 is an even number, so I take half: 8

J8 is an even number, so I take half: 4

J4 is an even number, so I take half: 2

J2 is an even number, so I take half: 1

The process took 6 steps to reach 1

Here's my code so far:

Thanks!

you will notice only references the char at the 0 position, if you want it to print along the entire string, you need to make it a variable index and increment it ever time through the loop.

Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH

I tried usingLes Morgan wrote:This line:

you will notice only references the char at the 0 position, if you want it to print along the entire string, you need to make it a variable index and increment it ever time through the loop.

, but that didn't work.

This was my output:

Please enter a number to start hail stone sequence: 42

John Dirt42 is an even number, so I take half: 21

John Dirt21 is an odd number, so I make 3n + 1: 64

John Dirt64 is an even number, so I take half: 32

John Dirt32 is an even number, so I take half: 16

John Dirt16 is an even number, so I take half: 8

John Dirt8 is an even number, so I take half: 4

John Dirt4 is an even number, so I take half: 2

John Dirt2 is an even number, so I take half: 1

The process took 8 steps to reach 1

You have the basic loop in your OP, you don't need another. What you do need is to change the chatAt(0) to a charAt(myVariable) and increment myVariable each time you go though your input loop.

Chase Harris wrote:

I tried usingLes Morgan wrote:This line:

you will notice only references the char at the 0 position, if you want it to print along the entire string, you need to make it a variable index and increment it ever time through the loop.

, but that didn't work.

This was my output:

Please enter a number to start hail stone sequence: 42

John Dirt42 is an even number, so I take half: 21

John Dirt21 is an odd number, so I make 3n + 1: 64

John Dirt64 is an even number, so I take half: 32

John Dirt32 is an even number, so I take half: 16

John Dirt16 is an even number, so I take half: 8

John Dirt8 is an even number, so I take half: 4

John Dirt4 is an even number, so I take half: 2

John Dirt2 is an even number, so I take half: 1

The process took 8 steps to reach 1

Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH

That really helped! Thank you. I still have a few small problems with my output though.Les Morgan wrote:Chase,

Here is a very basic loop structure and explanation of how it works.

Please enter a number to start hail stone sequence: 54

J 54 is an even number, so I take half: 27

O 27 is an odd number, so I make 3n + 1: 82

E 82 is an even number, so I take half: 41

41 is an odd number, so I make 3n + 1: 124

D 124 is an even number, so I take half: 62

I 62 is an even number, so I take half: 31

R 31 is an odd number, so I make 3n + 1: 94

T 94 is an even number, so I take half: 47

The input entered is not a number. Please run again.

It doesn't go through the whole sequence and at the bottom it says, "The input entered is not a number. Please run again."

Here's my coding:

Each time you loop, you increment i, and use it to find a character in the string.

Your loop had run eight times, and is still not done.

what happens on this line when i = 8?

System.out.print(s.charAt(i)+ " ");

and remember, the characters are in positions 0-7.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

I just noticed that for "if(i==s.length()) bLoop = false;" it has a yellow underline, which means it isn't being used. I'm guessing that's the problem?fred rosenberger wrote:You have the string "JOE DIRT", with eight characters.

Each time you loop, you increment i, and use it to find a character in the string.

Your loop had run eight times, and is still not done.

what happens on this line when i = 8?

System.out.print(s.charAt(i)+ " ");

and remember, the characters are in positions 0-7.

In your algorithm you cannot guarantee that you have a halting condition at the end of your String length, one thing you may do to elevate the unwanted consequences is to make your index circular--you can mod the index by the string length value, that will always guarantee that your index with be within the range of 0 to K-1, but your string will continuously cycle the output until you exit.

Les

Chase Harris wrote:

I just noticed that for "if(i==s.length()) bLoop = false;" it has a yellow underline, which means it isn't being used. I'm guessing that's the problem?fred rosenberger wrote:You have the string "JOE DIRT", with eight characters.

Each time you loop, you increment i, and use it to find a character in the string.

Your loop had run eight times, and is still not done.

what happens on this line when i = 8?

System.out.print(s.charAt(i)+ " ");

and remember, the characters are in positions 0-7.

Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH