Hi, I have been learning java for a couple of months... I have been trying to write a simple program that will print 6 numbers, in ascending order, on the console. I have these numbers in an array: int num[] = {46, 5, 17, 89, 77, 76} how do I do this?... Any help will be appreciated. Thanks
Do you want to print the numbers in the array, in ascending order, no matter how they are placed in the array? This would be so you can play with logic flow. Or do you just want to print those numbers in ascending order?
Rohit Gupta
Greenhorn
Joined: Sep 12, 2000
Posts: 2
posted
0
Yep, I want to use the logic flow...can you help me with some code? Thanks.
Originally posted by Steven YaegerII: Do you want to print the numbers in the array, in ascending order, no matter how they are placed in the array? This would be so you can play with logic flow. Or do you just want to print those numbers in ascending order?
Try this! import java.util.*; public class NewSortArray { public static void main(String[] args) { int[] num = {46,5,17,89,77,76}; Arrays.sort(num); for (int i = 5; i < num.length; --i) System.out.println(num[i]); } }