How to write this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to write this code?

I need to write a code to scan an integer from 1 to 100, then if n=1 output= I hate it, n=2 output = I hate that I love it, if n=3 output = I hate that I love that I hate it, and so on. I can't figure it out , I wrote a code but it only gives me a similar output not the one I need, would appreciate any help, still a newbie.

8th Oct 2019, 6:48 PM
Mustafa El-Shinhab
Mustafa El-Shinhab - avatar
13 Answers
+ 5
https://code.sololearn.com/c3iIVVXePbDU/?ref=app
8th Oct 2019, 8:19 PM
blACk sh4d0w
blACk sh4d0w - avatar
10th Oct 2019, 6:49 PM
Krishna
Krishna - avatar
+ 1
? Mustafa El-Shinhab Is the output supposed to be that if n = 3 I hate it I hate that I love it I hate that I love that I hate it Or I hate that I love that I hate it if its the second one my code works just fine
8th Oct 2019, 7:24 PM
Odyel
Odyel - avatar
+ 1
Kilowac lol yeah it works just fine, I wrote something wrong, great help thank you💘💘
8th Oct 2019, 7:55 PM
Mustafa El-Shinhab
Mustafa El-Shinhab - avatar
+ 1
Mustafa El-Shinhab No problem! Hope my comments helped :^)
8th Oct 2019, 7:57 PM
Odyel
Odyel - avatar
0
Can you post the code you tried?
8th Oct 2019, 6:58 PM
Odyel
Odyel - avatar
0
int n = 100; //input String s = ""; for(int i=0;i<n;i++){ if(i % 2 == 0){ s += "I hate that "; }else{ s += "I love it "; } } System.out.println(s);
8th Oct 2019, 6:58 PM
Anton Böhler
Anton Böhler - avatar
8th Oct 2019, 7:06 PM
Mustafa El-Shinhab
Mustafa El-Shinhab - avatar
0
Anton Böhler well it's similar but still not the output required.
8th Oct 2019, 7:12 PM
Mustafa El-Shinhab
Mustafa El-Shinhab - avatar
0
Kilowac it's much better code written but if you tried to run it, it's not close to the output required
8th Oct 2019, 7:20 PM
Mustafa El-Shinhab
Mustafa El-Shinhab - avatar
0
I love it
10th Oct 2019, 12:51 PM
hillary Kirimi
0
Write a code that will show balance, withdraw and deposit cash in a banl
10th Oct 2019, 12:52 PM
hillary Kirimi