How to multiply a digit with its position in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to multiply a digit with its position in java

Hi For example 123456789 first digit’s position is 10 and second 9 and... I want to do This for all of them Thanks

8th Mar 2019, 10:36 PM
Amir
Amir - avatar
7 Answers
+ 14
String a="123456789"; int b=0,c=10; for(int i=0;i<a.length();i++) { b = Integer.parseInt(""+a.charAt(i))*c; System.out.println(b); --c; } } I think this is you want Amir
8th Mar 2019, 11:11 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 12
Plz elabrate your qustion If you multiply every singal digit with 10 than do this First take a all number as a string than use one for loop and itrate upto all digit.length and take a every singal character in string using charAt method Example : String a="123456789"; int b = Integer.parseInt(""+a.charAt(0))*10; Output : 10;
8th Mar 2019, 10:55 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 10
No first character postion was always start with 0
8th Mar 2019, 11:00 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
Thank you Sumit but what mean is first digit’s position is ten and second is nine and so on.
8th Mar 2019, 10:58 PM
Amir
Amir - avatar
0
imagine the first digit from left with position 10. it is part of an algorithm.
8th Mar 2019, 11:04 PM
Amir
Amir - avatar
0
Thank you so much!!
8th Mar 2019, 11:14 PM
Amir
Amir - avatar
0
In Java ,the index position starts from zero.
9th Mar 2019, 12:15 AM
Home Number
Home Number - avatar