🔒 Closed Guys! Pa help sa code?

Status
Not open for further replies.

chiper

Grasshopper
Convert the following code to a user-defined class by using instance variables and methods.

***this Program is to Sort an Array in Ascending Order


import java.util.Scanner;
public class JavaExample
{
public static void main(String[] args)
{
int count, temp;

Scanner scan = new Scanner(System.in);
System.out.print("Enter number of elements you want in the array: ");
count = scan.nextInt();

int num[] = new int[count];
System.out.println("Enter array elements:");
for (int i = 0; i < count; i++)
{
num = scan.nextInt();
}
scan.close();
for (int i = 0; i < count; i++)
{
for (int j = i + 1; j < count; j++) {
if (num > num[j])
{
temp = num;
num = num[j];
num[j] = temp;
}
}
}
System.out.print("Array Elements in Ascending Order: ");
for (int i = 0; i < count - 1; i++)
{
System.out.print(num + ", ");
}
System.out.print(num[count - 1]);
}
}
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 404
    Views
  • 2
    Participants
Last reply from:
PHC_Jayvee

Online now

Members online
904
Guests online
681
Total visitors
1,585

Forum statistics

Threads
2,276,945
Posts
28,973,258
Members
1,229,658
Latest member
hihiwae
Back
Top