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.
13 Respostas
+ 5
https://code.sololearn.com/c3iIVVXePbDU/?ref=app
+ 3
Here is the code
https://code.sololearn.com/c5PMg3H816u9/?ref=app
+ 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
+ 1
Kilowac lol yeah it works just fine, I wrote something wrong, great help thank youđđ
+ 1
Mustafa El-Shinhab No problem! Hope my comments helped :^)
0
Can you post the code you tried?
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);
0
Anton Böhler well it's similar but still not the output required.
0
Kilowac it's much better code written but if you tried to run it, it's not close to the output required
0
I love it
0
Write a code that will show balance, withdraw and deposit cash in a banl