Hanna Roberts

Greenhorn
+ Follow
since Feb 09, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
1
Total given
9
Given in last 30 days
9
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Hanna Roberts

So I'm trying to make this code that's instructions were this:
Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4:
simonPattern: RRGBRYYBGY
userPattern:  RRGBBRYBGY

and this is the code I wrote but I keep getting a message that says something about char, I'll attach the photo below
Could someone help me fix this code?

1 day ago

Hanna Roberts wrote:So how would you make it for example take a decimal like 1.234567 and print it as 1.2346? because printf() is used for that too right?


nevermind about this I got it.
3 days ago
So how would you make it for example take a decimal like 1.234567 and print it as 1.2346? because printf() is used for that too right?
3 days ago
Oh ok thanks. And if I wanted a tab at the end would I just add \t after those %f?
4 days ago
So I was trying to use printf(); in this program but it gives me an error. Could someone explain why?
4 days ago

Carey Brown wrote:

Hanna Roberts wrote:So you’re saying any time I use nextLine() after a nextInt()  I will always have to flush it, so I write it twice?


Yes. This includes nextInt(), nextDouble(), etc., anything OTHER THAN nextLine().



Oh ok. Thank you!
1 week ago
So you’re saying any time I use nextLine() after a nextInt()  I will always have to flush it, so I write it twice?
1 week ago
So I was making this program and I was wondering if anyone knew why when I run it the inputting of the sentence is either skipped completely or it doesn't let me type in the sentence and end there.
Here's the code:



Also I'll attach a picture of the errors I was getting.
1 week ago

Junilu Lacar wrote:If you're trying to learn about nested if-statements, you wouldn't be using the ternary operator anyway.



oh ok
1 week ago

Campbell Ritchie wrote:

Hanna Roberts wrote:. . . it worked out well . . .

Well done

I would have used the ?: operator myself. It is easy enough to find the largest and smallest of three, which I did on JShell, but ran out of time and energy enough to work out the middle value.

jshell> int max(int i, int j, int k)
  ...> {
  ...>    return i > j ?
  ...>           i > k ? i : k :
  ...>           j > k ? j : k;
  ...> }
|  created method max(int,int,int)

jshell> max(123, 234, 345)
$5 ==> 345

jshell> max(123, 345, 234)
$6 ==> 345

jshell> max(345, 234 ,123)
$7 ==> 345

jshell> int min(int i, int j, int k)
  ...> {
  ...>    return i < j ?
  ...>           i < k ? i : k :
  ...>           j < k ? j : k ;
  ...> }
|  created method min(int,int,int)

jshell> min(345, 234 ,123)
$9 ==> 123

jshell> min(345, 123, 234)
$10 ==> 123

jshell> min(123, 345, 234)
$11 ==> 123

Remember that ?: is equivalent to an if‑else squashed into a single expression, and ?: expressions can be nested inside one another. Did you have a stipulation that the three values be different? A Scanner will accept an int with nextDouble() and convert an input like 123 to 123.0.



Thanks and oh I don't think I've learned that operator yet so I probably shouldn't use it yet.
1 week ago
so I ended up having this as my code:
]


it worked out well for my assignment. thanks for all the suggestions.
1 week ago
So I'm not sure what Im doing wrong in my code. I am trying to get the code to allow a user to type in three double numbers and then have the program put it in descending. This is the code I wrote:



So then I output the code (at least with the set of numbers I used) it has the correct largest and smallest value but for the middle value it sets it to 0. What is it that I am doing wrong in my code?
1 week ago

Carey Brown wrote:This doesn't make your answer wrong but as go along your Java learning curve you will notice that there are a lot of Java programming conventions. Following the conventions allows seasoned Java programmers to quickly read and understand the intent of the code. When you don't follow conventions it may still work but then the reader has to stop and analyze the code to understand why it was written differently, this can slow the reading process down enormously.

Another convention that popped up in your code is ++i. This is a per-increment instruction. Because there's no other larger expression that it is a part of it behaves the same as i++, a post-increment instruction. The convention is to always use post increment unless you are specifically doing something that requires pre-increment. Again, this is just one of those things you get used to but you'll find your reading and comprehension speed improving.



That makes sense. Thanks for letting me know
1 week ago
I was wondering how I could make a table that looks like the picture attached using for loops like in my program which I've added below:



1 week ago

Carey Brown wrote:

Hanna Roberts wrote:Oh I think I get the problem now. I had the sign backwards it need to be retireAge >= i; right?


Yes. But...

Usually the 'i' variable precedes the limit variable. So if you swap it around you get
i <= retireAge



Oh I see. Thanks.
1 week ago