<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: M Usama</title>
    <description>The latest articles on DEV Community by M Usama (@ditial-cordex).</description>
    <link>https://dev.to/ditial-cordex</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2966452%2Faffbf039-a420-4001-a0ba-9b4cbca14ad9.png</url>
      <title>DEV Community: M Usama</title>
      <link>https://dev.to/ditial-cordex</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ditial-cordex"/>
    <language>en</language>
    <item>
      <title>CGPA to Percentage Converter Using Java (Basic But Accurate)</title>
      <dc:creator>M Usama</dc:creator>
      <pubDate>Sat, 22 Mar 2025 17:06:55 +0000</pubDate>
      <link>https://dev.to/ditial-cordex/cgpa-to-percentage-converter-using-java-basic-but-accurate-fgh</link>
      <guid>https://dev.to/ditial-cordex/cgpa-to-percentage-converter-using-java-basic-but-accurate-fgh</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

public class CgpaToPercentageConverter {

    // Conversion factor (commonly used formula: Percentage = CGPA * 9.5)
    private static final double CONVERSION_FACTOR = 9.5;

    public static void main(String[] args) {
        // Create a Scanner object to read input from the user
        Scanner scanner = new Scanner(System.in);

        // Prompt the user to enter their CGPA
        System.out.print("Enter your CGPA: ");
        double cgpa = scanner.nextDouble();

        // Validate the input (CGPA should be between 0 and 10)
        if (cgpa &amp;lt; 0 || cgpa &amp;gt; 10) {
            System.out.println("Invalid CGPA! CGPA should be between 0 and 10.");
        } else {
            // Convert CGPA to percentage
            double percentage = cgpa * CONVERSION_FACTOR;

            // Display the result
            System.out.printf("Your percentage is: %.2f%%\n", percentage);
        }

        // Close the scanner to avoid resource leak
        scanner.close();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation of the Code:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Importing the Scanner Class:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We import the Scanner class from the java.util package to read input from the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining the Conversion Factor:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We define a constant CONVERSION_FACTOR with a value of 9.5. This is a commonly used factor to convert CGPA to percentage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main Method:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main method is the entry point of the program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Scanner Object:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We create a Scanner object named scanner to read input from the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompting the User for Input:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We prompt the user to enter their CGPA using System.out.print.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reading the CGPA Input:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use scanner.nextDouble() to read the CGPA value entered by the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Validation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We check if the entered CGPA is within the valid range (0 to 10). If not, we display an error message.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Calculating the Percentage:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
If the CGPA is valid, we calculate the percentage by multiplying the CGPA by the conversion factor (9.5).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Displaying the Result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use System.out.printf to display the calculated percentage with two decimal places.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closing the Scanner:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, we close the Scanner object to free up resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Run the Program:&lt;/strong&gt;&lt;br&gt;
Copy the code into a file named CgpaToPercentageConverter.java.&lt;/p&gt;

&lt;p&gt;Compile the program using the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;javac CgpaToPercentageConverter.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the program using the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java CgpaToPercentageConverter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter your CGPA when prompted, and the program will display the corresponding percentage.&lt;br&gt;
Example Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Enter your CGPA: 8.5
Your percentage is: 80.75%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the end, you will get the CGPA to Percentage converter like &lt;a href="https://cgpaintopercentages.com/" rel="noopener noreferrer"&gt;https://cgpaintopercentages.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
    </item>
  </channel>
</rss>
