কম্পিউটার

জাভা প্রোগ্রাম কী দ্বারা মানচিত্র সাজানোর জন্য


এই নিবন্ধে, আমরা কী দ্বারা মানচিত্র বাছাই কিভাবে বুঝতে হবে. জাভা ম্যাপ ইন্টারফেস, java.util.Map, একটি কী এবং একটি মানের মধ্যে একটি ম্যাপিং উপস্থাপন করে। আরও নির্দিষ্টভাবে, একটি জাভা ম্যাপকান কী এবং মানগুলির জোড়া সঞ্চয় করে। প্রতিটি কী একটি নির্দিষ্ট মানের সাথে সংযুক্ত।

নীচে একই -

এর একটি প্রদর্শন রয়েছে৷

ধরুন আমাদের ইনপুট হল

Input map: {1=Scala, 2=Python, 3=Java}

কাঙ্খিত আউটপুট হবে

The sorted map with the key:
{1=Scala, 2=Python, 3=Java}

অ্যালগরিদম

Step 1 - START
Step 2 - Declare namely
Step 3 - Define the values.
Step 4 - Create a Map structure, and add values to it using the ‘put’ method.
Step 5 - Create a TreeMap of strings.
Step 6 - The Map sorts the values based on keys and stores it in TreeMap.
Step 7 - Display this on the console.
Step 8 - Stop

উদাহরণ 1

এখানে, আমরা 'প্রধান' ফাংশনের অধীনে সমস্ত ক্রিয়াকলাপ একসাথে আবদ্ধ করি।

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class Demo {
   public static void main(String[] args) {
      System.out.println("The required packages have been imported");
      Map<String, String> input_map = new HashMap<>();
      input_map.put("1", "Scala");
      input_map.put("3", "Java");
      input_map.put("2", "Python");
      System.out.println("The map is defined as: " + input_map);
      TreeMap<String, String> result_map = new TreeMap<>(input_map);
      System.out.println("\nThe sorted map with the key: \n" + result_map);
   }
}

আউটপুট

The required packages have been imported
The map is defined as: {1=Scala, 2=Python, 3=Java}

The sorted map with the key:
{1=Scala, 2=Python, 3=Java}

উদাহরণ 2

এখানে, আমরা ক্রিয়াকলাপগুলিকে অবজেক্ট ওরিয়েন্টেড প্রোগ্রামিং প্রদর্শনকারী ফাংশনে অন্তর্ভুক্ত করি৷

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class Demo {
   static void sort( Map<String, String> input_map){
      TreeMap<String, String> result_map = new TreeMap<>(input_map);
      System.out.println("\nThe sorted map with the key: \n" + result_map);
   }
   public static void main(String[] args) {
      System.out.println("The required packages have been imported");
      Map<String, String> input_map = new HashMap<>();
      input_map.put("1", "Scala");
      input_map.put("3", "Java");
      input_map.put("2", "Python");
      System.out.println("The map is defined as: " + input_map);
      sort(input_map);
   }
}

আউটপুট

The required packages have been imported
The map is defined as: {1=Scala, 2=Python, 3=Java}

The sorted map with the key:
{1=Scala, 2=Python, 3=Java}

  1. গণনা সাজানোর জন্য জাভা প্রোগ্রাম

  2. বাইনারি সন্নিবেশ সাজানোর জন্য জাভা প্রোগ্রাম

  3. ককটেল সাজানোর জন্য জাভা প্রোগ্রাম

  4. প্যালিনড্রোম চেক করতে জাভা প্রোগ্রাম