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,...
๐ก Explanation:
In this program, we use a for loop to print all alphabets from A to Z.
In Java, characters have ASCII values.
-
'A'starts from 65 -
'Z'ends at 90
We can use a loop to print them in sequence.
✅ Java Program:
public class AlphabetsAtoZ {
public static void main(String[] args) {
System.out.println("Alphabets from A to Z are:");
for (char ch = 'A'; ch <= 'Z'; ch++) {
System.out.print(ch + " ");
}
}
}
๐ง How It Works:
-
The loop starts with
ch = 'A'. -
It continues until
ch <= 'Z'. -
In each iteration, the character is printed and then incremented.
-
'A'becomes'B','B'becomes'C', and so on until'Z'.
๐ฅ️ Output:
Alphabets from A to Z are:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Comments
Post a Comment