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,945 questions

51,887 answers

573 users

How to read multiple integers from a single line of input in Java

1 Answer

0 votes
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class MyClass {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String  lines = br.readLine();    
        
        String[] arr = lines.trim().split("\\s+");
            
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Integer.parseInt(arr[i]));
        }
    }
}
 
 
 
 
/*
run:
 
123
890
3
7
98
 
*/


 



answered Oct 22, 2023 by avibootz

Related questions

1 answer 87 views
1 answer 127 views
1 answer 129 views
3 answers 288 views
1 answer 205 views
1 answer 154 views
1 answer 195 views
...