Help With Java, Using arrays (i think)?

Help With Java, Using arrays (i think)?
Hello, I am trying to write a program where 9 digits are imputed by the user and last symbol is calculated from the previous digits, here is the algorithm:
First sum the first digit, and 2 times the second digit, plus 3 times the third digit, etc, to 9 times the ninth digit. Then I have to divide the sum by 11 and if it is less than 10 then the remainder becomes the sum, other wise it is the symbol

Here’s what i have so far

public class ISBN
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
String isbn;
isbn=scan.nextLine();

It is here where I am not sure how to read the individual values of the string and begin the calculations of the algorithm. I was thinking about using an array but i am not too sure how to use it. Any help is appreciated, thanx.

Best answer:

Well, for all practical purposes you’ve already got the data in an array. Peel off the digits one at a time from the String (by treating the String as an array and accessing the characters via an index), convert them to integer, and perform the requested operations.

Tags: , , , ,

Under Forum

Leave a Comment for Help With Java, Using arrays (i think)?

You must be logged in to post a comment.

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories