I'm trying to code an array that will make user print in 125 digits and then add the sum of it, this works but im trying to make the message like:

Please enter digit : 1
please enter digit : 2
Please enter digit : 3
...

Do i have to make a new int for this to work?

this is my current code

import java.util.Scanner;
public class jasam {
    public static void main (String[] args) {
        Scanner scan = new Scanner(System.in);
int[] array = new int [125];
int sum = 0;
int counter = 0;

while(sum < 125){
    System.out.println("Please enter digit:" );
    array[counter]=scan.nextInt();

    sum += array[counter];

That's OK so far... except do you really want to stop taking input when the sum reaches 125?

ps System.out.print is just like System.out.println except it doesn't go to a new line at the end, so it would look more like the sample input in your post

Yes I want it to end by 125 so do you know how i make it look like the sample?

does this work for you? this program also traps invalid input(s),
and display the contents of array...if you don't need to display the items of the array, i bet it's ok if you don't put the numbers in the array and just simply add up everything...

/*
*@author:Giselle Jane Noynay
*/
import java.util.Scanner;
public class jasam
{
   public static void main(String[] args)
   {
      int counter=0;
      int sum=0;  
      Scanner scan=new Scanner(System.in);
      int arr[]=new int[125];
      while(counter<125)
      {
            try
            {  

               System.out.print("Please enter integer number "+ (counter + 1)+ ": ");
               arr[counter]=scan.nextInt();
               sum+=arr[counter];
               ++counter;
            }
            catch(Exception e)
            {
               System.out.println("Input integers only.");
               scan.nextLine();//FLUSHES INVALID INPUT

            }


      }
      //TO DISPLAY ITEMS IN ARRAY
      for(int i=0;i<arr.length;i++)
      {
         System.out.println(arr[i]);
      }
      System.out.println("Sum is: " + sum);
   }
}

That what was i needed help with, thank you very much!

not a problem...glad i'm able to help ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.