need more clarity

Status
Not open for further replies.

Denise_33

Prominent
Feb 24, 2017
1
0
510
Ok I'm trying to figure out this problem using a t-chart
for (int i = 1; i < 5; i++)
for(int k = i; k > 2; k--)
System.out.print(k + "");

My t-chart

i
1
2
3
4
5


K
-
-
2
3
4


output

2 3 4

suppose to be

3 4 3 how???





 
Solution
False logic it looks like. Your second for loop has k=i, i=1. So k has to be bigger than or equal to 2. So it is doing what you have coded. If you want 3,4,3, there is no math statement that is going to go from 3 to 4 to 3. However, you might be able to set an if statement that says if it is bigger than 4, print 4. I program in python, but this is java I think. I think this is the wrong forum for this question though. Try stack overflow. That is a programming community. Also, try explaining more about what you're trying to do or else no one will respond to you over in stack overflow.

Nerdy Nerd

Reputable
Mar 19, 2016
814
0
5,360
False logic it looks like. Your second for loop has k=i, i=1. So k has to be bigger than or equal to 2. So it is doing what you have coded. If you want 3,4,3, there is no math statement that is going to go from 3 to 4 to 3. However, you might be able to set an if statement that says if it is bigger than 4, print 4. I program in python, but this is java I think. I think this is the wrong forum for this question though. Try stack overflow. That is a programming community. Also, try explaining more about what you're trying to do or else no one will respond to you over in stack overflow.
 
Solution
Status
Not open for further replies.