Totalling numbers from a String – Java

Within this program it will take in 3 numbers and store them as strings. At the end of the program it will then print out an overall total of all the numbers which have been entered.

public class ConvertingStrings
   public static void main(String[] args)
      Scanner keyboard = new Scanner(;
      String [] numbers = new String[3];

      int count;
      int total =0;
      int number;
      final int SIZE = 3;

      //Getting String numbers
      for (count=0; count < SIZE;count++)
         System.out.println("Please enter String number "+(count+1));
         numbers[count] = keyboard.nextLine();

         number = Integer.parseInt(numbers[count]);

         total += number;


      System.out.println("Overall total is: "+total);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s