Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to store Scanner input number into an array in Java

1 Answer

0 votes
import java.util.Scanner;

public class MyClass {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int size = 3;
        
        int[] numbers = new int[size];

        for (int i = 0; i < size; i++) {
            System.out.print("Enter a number: ");
            numbers[i] = scanner.nextInt();
        }

        System.out.println("The numbers are: ");
        for (int number : numbers) {
            System.out.println(number);
        }
    }
}


 
 
/*
run:
      
Enter a number: 23
Enter a number: -7843 
Enter a number: 9817236
The numbers are: 
23
-7843
9817236
      
*/

 



answered Oct 6, 2023 by avibootz

Related questions

1 answer 97 views
2 answers 108 views
108 views asked Nov 6, 2023 by avibootz
2 answers 181 views
2 answers 156 views
156 views asked Jun 2, 2023 by avibootz
1 answer 105 views
2 answers 142 views
...