Looking For Anything Specific?

ads header

Java Program Examples

 1.  Java program to check whether input character is vowel or consonant.

class vowelconsonent {

public static void main (){

char 'a';

if(ch=='a' || ch =='e' || ch =='i' || ch =='o' || ch =='u'){

System.out.println(ch + "is vowel"); 

}

else {

System.out.println(ch + "is consonant");

} }

Watch here : click here

 2.  Java program for substraction of two numbers.

public class sample {

public static void main (String[] args){

int a;

int b;

System.out.println("Enter two numbers: ");

System.out.println(a + " " + b);

int c=a-b;

System.out.println("Result is:" + c);

} }

Watch here : click here

 3.  Java program for swapping two numbers using temporary variable.

public class swap{

    public static void main(String[] args){

        int first=5;

        int second=10; 

        System.out.println("---Before Swap---");

        System.out.println("first no - " + first);

        System.out.println("secont no - " + second);  

        //first value is assigned to temporary

         int temp = first;

        //second value is assigned to first

         first = second;

       //temporary value us assigned to second

        second = temp;       

        System.out.println("---After Swap---");

        System.out.println("first no - " + first);

        System.out.println("secont no - " + second);

        System.out.println(" ");              

        System.out.print("@codewithmanshi");

  }

}

Watch here : click here

 4.  Java Program to check whether input number is even or odd.

import java.util.Scanner;

public class EvenOdd {

    public static void main(String[] args) {

        Scanner reader = new Scanner(System.in);

        System.out.print("Enter a number: ");

        int num = reader.nextInt();

        if(num % 2 == 0) {

        System.out.println(num + " is even");

        }

        else {

        System.out.println(num + " is odd");

        }

        System.out.println("@codewithmanshi");

    }

}

Watch Here : click here

Post a Comment

0 Comments