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

51,831 answers

573 users

How to use formatted console output in Java

3 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        int[] arr = new int[] {2, 5, 3, 5, 5, 1, 5, 7, 3};
 
        for (int i = 0; i < arr.length; i++) {
             System.out.printf("%d : %d\n", i, arr[i]);
        }
    }
}



/*
run:

0 : 2
1 : 5
2 : 3
3 : 5
4 : 5
5 : 1
6 : 5
7 : 7
8 : 3

*/

 



answered Feb 22, 2019 by avibootz
edited Feb 22, 2019 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        int[] arr = new int[] {2, 5, 3, 5, 5, 1, 5, 7, 3};
 
        String output;
        for (int i = 0; i < arr.length; i++) {
             output = String.format("%d : %d", i, arr[i]);
             System.out.println(output);
        }
    }
}



/*
run:

0 : 2
1 : 5
2 : 3
3 : 5
4 : 5
5 : 1
6 : 5
7 : 7
8 : 3

*/

 



answered Feb 22, 2019 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        int[] arr = new int[] {2, 5, 3, 5, 5, 1, 5, 7, 3};
 
        for (int i = 0; i < arr.length; i++) {
             System.out.format("%d : %d\n", i, arr[i]);
        }
    }
}



/*
run:

0 : 2
1 : 5
2 : 3
3 : 5
4 : 5
5 : 1
6 : 5
7 : 7
8 : 3

*/

 



answered Feb 22, 2019 by avibootz

Related questions

1 answer 140 views
140 views asked Jul 23, 2016 by avibootz
3 answers 286 views
1 answer 146 views
146 views asked Jun 11, 2015 by avibootz
1 answer 111 views
111 views asked Apr 1, 2021 by avibootz
1 answer 172 views
...