Basic Java Programs

Hello Everyone,

This is my first time in WordPress and I am quite excited about this. My first post is about basic java programs and I hope it is useful for the basic java learners.

So,lets starts Programming,

  1. The First Programm is about how to Print no.1 five times using looping method.

public class Oneprinted5times {

public static void main(String[] args) {
    int count=1,a=1;
    while(count<=5) {
        System.out.println(a);
        count++;
    }
    // TODO Auto-generated method stub

}

2.The Second Programm is about how to Print from 1 to 5 using looping method.

public class Print1to5 {

public static void main(String[] args) {
    int a=1;
    while(a<=5) {
        System.out.println(a);
        a++;

    }
    // TODO Auto-generated method stub

}
}

3.Now, we are going to do Program with Even numbers with Looping Method.

public class Evenno {

public static void main(String[] args) {
    int no=2;
    while(no<=10) {
        System.out.println(no);
        no+=2;
    }
    // TODO Auto-generated method stub


}
}

4. Done with Even number so we moved to odd numbers.

public class Oddno {

public static void main(String[] args) {
int no=1;
while(no<=10)
{
System.out.println(no);
no+=2;
}

}

}

5. Now we going Print odd and even numbers continuously.

public class Oddeven {

public static void main(String[] args) {
    int no=1;
    while(no<=10) {
        System.out.println(no);
        no+=2;
        if(no==11) {
            no=2;
        }
    }
    // TODO Auto-generated method stub

}
}

Leave a comment

Design a site like this with WordPress.com
Get started