Skip to main content

Write a Program in java to sort a list of items in ascending order

Write a Program in java to sort a list of items in ascending order.



class sortList{ 
public static void main(String[] args) { 
int A[]={1,2,6,4,8,7,9}; 
System.out.println("Original List : "); 
printArray(A); 
System.out.println(); 
assendingOrder(A); 
System.out.println("List in ascending order : "); 
printArray(A); 
public static void printArray(int A[]){ 
for(int i=0;i<A.length;i++){ 
System.out.print(A[i]+"\t"); 
public static void assendingOrder(int A[]){ 
int a; 
for(int i=0;i<A.length;i++){ 
for(int j=i;j<A.length;j++){ 
if(A[i]>A[j]){ 
a=A[i]; 
A[i]=A[j]; 
A[j]=a; 
}


OUTPUT:

Original List :
1    2    6    4    8    7    9
List in ascending order :
1    2    4    6    7    8    9



Comments

Popular posts from this blog

Book Photography Tips

বইছবি সুন্দর করার জন্য কয়েকটি পরামর্শঃ ১। প্রথম তো দিনের আলোতে বইয়ের ছবি তুলুন। গুমোট অন্ধকারে তোলা ছবির লুক ভালো আসে না। রাতে লাইটের আলোতে তোলা ছবির লুকও যথেষ্ট ভালো আসে না। ২। যে বইটার ছবি তুলবেন, শুধুমাত্র ঐ বইটার দিকে ক্যামেরার ফোকাস রাখুন। ডেকোরেশনের জন্য অন্য বই সাথে রাখতে পারেন, কিন্তু ঐসকল বইয়ের নাম যেন দেখা না যায়। ঐসকল বইয়ের পেছনের মলাট খোলা রেখে ছবি তুলুন। একটা বই উল্টো করে অন্য বইটা ঢেকে দিন। ৩। বইয়ের বেকগ্রাউন্ডে পুরোপুরি সাদা বা এক কালারের রঙিন কাপড় বিছিয়ে ছবি তুলুন। ছবির সৌন্দর্য অনেকগুণ বাড়বে। ৪। পারতপক্ষে বইয়ের সাথে দু-একটি বুকমার্ক রাখুন। ছবি মানানসই দেখাবে। ৫। সৌন্দর্য বৃদ্ধির জন্য প্রয়োজনীয় উপকরণ যেমন:  চায়ের কাপ, মগ, কালার পেপার, ফুল, রঙিন পাতা, ইত্যাদি আনুষঙ্গিক জিনিসপত্র সাথে রেখে ডেকোরেশন করে এরপর বইয়ের ছবি তুলুন। আগের চেয়ে বেটার আসবে ছবি। ৬। ছবি তোলার আগে উপকরণগুলো বিভিন্ন পজিশনে সাজিয়ে নিন। কোনো উপকরণ দুটোর বেশি রাখবেন না। হিজিবিজি দেখাবে। আবার অনেকগুলো উপকরণ সাথে রেখে ছবি তুলতে যাবেন না। বেমানান লাগবে। ৭। বইয়ের বিষয়বস্তুর সাথে খাপ খায় এমন শব্দ, বাক্য সাদা...

SQL Injection

SQL Injection The SQL Injection is a code penetration technique that might cause loss to our database. It is one of the most practiced web hacking techniques to place malicious code in SQL statements, via webpage input. SQL injection can be used to manipulate the application's web server by malicious users. SQL injection generally occurs when we ask a user to input their username/userID. Instead of a name or ID, the user gives us an SQL statement that we will unknowingly run on our database. For Example - we create a SELECT statement by adding a variable "demoUserID" to select a string. The variable will be fetched from user input (getRequestString). demoUserI = getrequestString("UserId"); demoSQL = "SELECT * FROM users WHERE UserId =" +demoUserId; Types of SQL injection attacks SQL injections can do more harm other than passing the login algorithms. Some of the SQL injection attacks include: Updating, deleting, and inserting the data: An attack can mo...

List vs Tuple

List vs Tuple (Image by - Sharma Guides | Subham232330) List | |- Syntax :- [2,3,4] | |- Mutable :- Elements can be changed after creation. | |- Length :- Variable length. | |- Memory :- List takes more memory than a tuple. Tuple | |- Syntax :- (2,3,4) | |- Immutable :- Elements cannot be changed after creation. | |- Length :- Fixed length. | |- Memory :- It takes less memory than a list.