Saturday, 1 April 2017

Simple Java program to find Prime number

This program has made simple for better understanding of beginners.

import java.util.Scanner;


public class PrimeNumber {
public static void main(String args[]){
System.out.println("Enter the number: ");
//To receive input from users
Scanner s = new Scanner(System.in);
int num = s.nextInt();
s.close();
//Logic to detect the prime number
for(int i=2; i<num; i++){
int temp = num%i;
if (temp == 0){
System.out.println("This is not a prime number.");
break;
else{
if (i == (num-1)){
System.out.println("This is a prime number.");
}
}
}


}

Output:
Enter the number: 
21
This is not a prime number.

Enter the number: 
3
This is a prime number.

Simple Java program for Odd or Even

This program has been simplified for beginners to find the given number is Odd or Even.

import java.util.Scanner;


public class OddrEven {
public static void main(String args[]){
//To get the input number from user
System.out.println("Enter the number: ");
Scanner sc = new Scanner(System.in);
int inp = sc.nextInt();
sc.close();
//Simple logic to check the number is Odd or Even
int temp = inp % 2;
if (temp == 0){
System.out.println("This is a even number.");
}else{
System.out.println("This is a odd number.");
}
}

}

Output:
Enter the number: 
45
This is a odd number.

Enter the number: 
22
This is a even number.

Expense Handler Application with advance technologies

Budget Planner  One of the application developed with Ionic 4 and Python-Flask.  Ionic 4 code:  https://github.com/logeshbuiltin/Expense...