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:" );

    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

Edited 2 Years Ago by JamesCherrill

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];

               System.out.print("Please enter integer number "+ (counter + 1)+ ": ");
            catch(Exception e)
               System.out.println("Input integers only.");
               scan.nextLine();//FLUSHES INVALID INPUT


      for(int i=0;i<arr.length;i++)
      System.out.println("Sum is: " + sum);
This article has been dead for over six months. Start a new discussion instead.