কম্পিউটার

জাভা প্রোগ্রাম একটি পূর্ণসংখ্যার সংখ্যা গণনা করার জন্য


এই নিবন্ধে, আমরা বুঝব কিভাবে একটি পূর্ণসংখ্যার সংখ্যা গণনা করা যায়। একটি পূর্ণসংখ্যার অঙ্কগুলি একটি লুপ এবং একটি কাউন্টার ব্যবহার করে গণনা করা হয়৷

নীচে একই -

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

ইনপুট

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

Number : 15161718

আউটপুট

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

The result is : 8

অ্যালগরিদম

Step 1 - START
Step 2 – Declare two integer values namely my_count and my_input.
Step 3 - Read the required values from the user/ define the values
Step 4 – Using a for loop, divide the input value by 10 until the number is reduced to its
lowest possible value. Increment the counter value each time.
Step 5- Display the counter value as result
Step 6- Stop

উদাহরণ 1

এখানে, একটি প্রম্পটের উপর ভিত্তি করে ব্যবহারকারী দ্বারা ইনপুট প্রবেশ করানো হচ্ছে। আপনি আমাদের কোডিং গ্রাউন্ড টুলে এই উদাহরণ লাইভ চেষ্টা করতে পারেন জাভা প্রোগ্রাম একটি পূর্ণসংখ্যার সংখ্যা গণনা করার জন্য

import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
      int my_count , my_input;
      my_count = 0;
      System.out.println("Required packages have been imported");
      Scanner my_scanner = new Scanner(System.in);
      System.out.println("A reader object has been defined ");
      System.out.print("Enter the number : ");
      my_input = my_scanner.nextInt();
      for (; my_input != 0; my_input /= 10, ++my_count) {
      }
      System.out.println("The number of digits in the given input is: " + my_count);
   }
}

আউটপুট

Required packages have been imported
A reader object has been defined
Enter the number : 15161718
The number of digits in the given input is : 8

উদাহরণ 2

এখানে, পূর্ণসংখ্যা পূর্বে সংজ্ঞায়িত করা হয়েছে, এবং এর মান অ্যাক্সেস করা হয়েছে এবং কনসোলে প্রদর্শিত হয়েছে।

public class Main {
   public static void main(String[] args) {
      int my_count = 0, my_input;
      my_count = 0;
      my_input = 15161718;
      System.out.println("The number is defined as " +my_input);
      for (; my_input != 0; my_input /= 10, ++my_count) {
      }
      System.out.println("The number of digits in the given input is: " + my_count);
   }
}

আউটপুট

The number is defined as 15161718
The number of digits in the given input is: 8

  1. জাভা প্রোগ্রাম একটি স্ট্রিং মধ্যে স্বর গণনা

  2. জাভাতে সংখ্যা গণনা করার জন্য একটি প্রোগ্রাম কীভাবে বাস্তবায়ন করবেন?

  3. একটি প্রদত্ত সংখ্যা N-এ অঙ্কের সংখ্যা গণনা করতে পাইথনে একটি প্রোগ্রাম লিখুন

  4. পাইথনে n সংখ্যার ধাপের সংখ্যা গণনা করার প্রোগ্রাম