Cant find the problem to this | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
3rd Jul 2020, 10:56 PM
Victor Yegon
Victor Yegon - avatar
6 ответов
+ 5
import java.util.Scanner; class stringReverse { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); char[] v=s.toCharArray(); for(int i=v.length;i>=1;i--) { System.out.print(v[i-1]); } } }
3rd Jul 2020, 11:19 PM
Reivin
Reivin - avatar
+ 2
Nice it worked thanks guyz
4th Jul 2020, 12:05 AM
Victor Yegon
Victor Yegon - avatar
+ 2
Thanks Martin Taylor that works too
4th Jul 2020, 12:16 AM
Victor Yegon
Victor Yegon - avatar
+ 1
Thanks Reivin Dedstinguer though still it has errors even after changing the char name
3rd Jul 2020, 11:58 PM
Victor Yegon
Victor Yegon - avatar
+ 1
What characters blackwinter?
3rd Jul 2020, 11:59 PM
Victor Yegon
Victor Yegon - avatar
+ 1
The for loop was already got an i-- statement so you don't need to decrease i again. The last item of an array has an index of the decreament of the array length by 1. So item array[array.length] doesn't exists, that also makes you mistake at i>=1 since 1 is index of the second item of an array has more than 2 items.
4th Jul 2020, 3:00 PM
Gaming2nd
Gaming2nd - avatar