Three Ways to Print Alphabet in Java using ( For Loop | While Loop | Do While Loop) - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Sunday, June 28, 2020

Three Ways to Print Alphabet in Java using ( For Loop | While Loop | Do While Loop)

Print Alphabet using For Loop : 
public class Alphabet {
    public static void main(String[] args) {
        for (char ch='a';ch<='z';ch++){   // capital letter type 'A' and 'Z'
            System.out.print(ch+" ");
        }
  }
}

Output : 


Print Alphabet using While Loop : 
public class Alphabet {
    public static void main(String[] args) {
        char a='a';
        while (a<='z'){
            System.out.println(a+" ");
            a++;
        }
    }
}
Output : 




Print Alphabet using Do While Loop :
public class Alphabet {
    public static void main(String[] args) {
        char a='a';
        do{
            System.out.println(a+" ");
            a++;
        }while (a<='z');
    }
}
Output : 
Note : if you want to write capital latter alphabet then type 'A' and 'Z' instead of  'a' and 'z'. 


Start with your Choice

-Important Programs for Freshers

Sorting and Searching Programs

Learn Pattern Programs 

Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

Learn with us | HTML | CSS | Java Script | Bootstrap | JAVA | ADV JAVA | SQL | GIT

No comments:

Pages