Skip to main content

Python print() Function

When you start learning Python, one of the first things you need to learn is how to display information on the screen. For example, you might want to display: A welcome message. Your name and age. The result of a mathematical calculation. Student marks and results. Information generated by a Python program. Python provides a built-in function called print() for displaying information. The print() function is one of the simplest and most frequently used functions in Python. It helps programmers display information while testing programs, solving problems, and developing applications. In this article, we will learn how to use print() with practical examples and their outputs. 1. What Is the print() Function in Python? The print() function is a built-in Python function that displays information in the output area, usually the terminal or console. Let's look at a simple example. print("Hello, World!") Output: Hello, World! In this example, Python displays the text Hello,...

Abundant Number Program in Java (With Explanation & Dry Run)

πŸ“Œ Introduction

In Java number programs, Abundant Number is an important topic often asked in BCA exams, viva, and interviews.
In this article, you will learn what an abundant number is, how to check it using Java, along with clear explanation and dry run.


πŸ”’ What Is an Abundant Number?

A number is called an Abundant Number if the sum of its proper divisors is greater than the number itself.

πŸ‘‰ Proper divisors are the divisors excluding the number itself.


🧠 Example of Abundant Number

Example 1

Number = 12
Proper divisors = 1, 2, 3, 4, 6
Sum = 1 + 2 + 3 + 4 + 6 = 16

Since 16 > 12,
✅ 12 is an Abundant Number

Example 2

Number = 8
Proper divisors = 1, 2, 4
Sum = 7

Since 7 < 8,
❌ 8 is NOT an Abundant Number


🧩 Algorithm to Check Abundant Number

  1. Start

  2. Read a number

  3. Initialize sum = 0

  4. Find all divisors from 1 to number/2

  5. If divisor divides number completely, add it to sum

  6. If sum > number → Abundant Number

  7. Else → Not Abundant

  8. End


πŸ’» Java Program to Check Abundant Number

import java.util.Scanner;

public class AbundantNumber {
    public static void main(String[] args) {
        int number, sum = 0;

        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        number = sc.nextInt();

        for (int i = 1; i <= number / 2; i++) {
            if (number % i == 0) {
                sum = sum + i;
            }
        }

        if (sum > number) {
            System.out.println(number + " is an Abundant Number");
        } else {
            System.out.println(number + " is NOT an Abundant Number");
        }
    }
}

πŸ§ͺ Dry Run

Input

number = 12
sum = 0
iDivides 12?sum
1Yes1
2Yes3
3Yes6
4Yes10
6Yes16

Final Check

sum = 16 > 12

✅ 12 is an Abundant Number


πŸ–₯️ Output

Enter a number: 12
12 is an Abundant Number

πŸ“š Types of Numbers (For Better Understanding)

TypeCondition
Perfect NumberSum of divisors = number
Deficient NumberSum of divisors < number
Abundant NumberSum of divisors > number

🎯 Important Exam Points

  • Proper divisors exclude the number itself

  • Loop runs till number/2

  • Time Complexity: O(n)

  • Common examples: 12, 18, 20, 24

Comments

Popular posts from this blog

Understanding Comments in Java: A Beginner’s Guide

When learning Java programming, one of the first concepts you’ll come across is comments . Comments may not affect how a program runs, but they play a crucial role in making code more understandable, readable, and maintainable. Let’s dive deeper into what comments are, why they’re important, and the different types of comments in Java. What are Comments in Java? A comment in Java is a piece of text written within a program that is ignored by the compiler . In other words, comments are notes for humans, not instructions for machines. They help developers explain the purpose of code, describe logic, or temporarily disable certain lines of code without deleting them. Why are Comments Important? πŸ“Œ Readability – Comments make code easier to understand for you and others. πŸ“Œ Maintenance – When you revisit your code after months, comments remind you what you were doing. πŸ“Œ Collaboration – In team projects, comments explain code to fellow developers. πŸ“Œ Debugging – You c...

Java Program to Check Voting Eligibility

In this program, we’ll take the user’s age as input and check whether the person is eligible to vote or not. In India, the minimum age required to vote is 18 years . πŸ’» Program Code // Java Program to Check Voting Eligibility import java.util.Scanner; public class VotingEligibility { public static void main(String[] args) { // Create Scanner object to take input from user Scanner sc = new Scanner(System.in); // Ask user to enter age System.out.print("Enter your age: "); int age = sc.nextInt(); // Check eligibility if (age >= 18) { System.out.println("You are eligible to vote."); } else { System.out.println("You are not eligible to vote yet."); System.out.println("You can vote after " + (18 - age) + " year(s)."); } sc.close(); // Close the scanner } } 🧠 Explanation import java.util.Scanner; → Imp...

Java Program to Calculate Total Marks and Average of Five Subjects

πŸ’‘ Program Explanation In this program: The user will input marks of five subjects . The program will calculate the total marks and average . It will then display both results clearly. πŸ§‘‍πŸ’» Java Code: // Java Program to Calculate Total Marks and Average of Five Subjects import java.util.Scanner; // Importing Scanner class for user input public class TotalAndAverage { public static void main(String[] args) { // Creating Scanner object to take input from user Scanner sc = new Scanner(System.in); // Declaring variables for five subjects double subject1, subject2, subject3, subject4, subject5; // Taking marks input for each subject System.out.print("Enter marks of Subject 1: "); subject1 = sc.nextDouble(); System.out.print("Enter marks of Subject 2: "); subject2 = sc.nextDouble(); System.out.print("Enter marks of Subject 3: "); subject3 = sc.nextDo...