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
7 Antworten
+ 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
+ 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;
+ 10
No first character postion was always start with 0
+ 1
Thank you Sumit but what mean is first digit’s position is ten and second is nine and so on.
0
imagine the first digit from left with position 10. it is part of an algorithm.
0
Thank you so much!!
0
In Java ,the index position starts from zero.