Sunday, 5 November 2017

jav program that check leap year or not



Problem 10:
Write a program that take year from the user and check it is leap or not
Discripition:
If year modulus 4 is equal to zero then year is leap.
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
   System.out.println("Enter the year");
    int num=input.nextInt();
    if(num%4==0)
    System.out.println("This is leap year "+num);
    else
        System.out.println("This is not leap year "+num);
 }}
Output:
                      


java program that check number is even or odd



Problem 09:
Write a program that check number is even or odd
Discripition:
If number mode 2 is zero number is positive other the number is negative.
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
   System.out.println("Enter five  number");
    int num=input.nextInt();
    if(num%2==0)
    System.out.println("The  number  "+num+" is even");
    else
        System.out.println("The  number  "+num+" is odd");
 }}
Output:
                         


java full important program find max and min number



Problem 08:
Write a program that take five number from user and find maximum number from it.
Discripition:
Declared  max and min assign the value of first number to max and min compare with all this number.
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
   System.out.println("Enter five  number");
    int num=input.nextInt();
    int num1=input.nextInt();
    int num2=input.nextInt();
    int num3=input.nextInt();
    int num4=input.nextInt();
    int max,min;
    max=min=num;
    if(max<num1)
        max=num1;
    if(max<num2)
        max=num2;
    if(max<num3)
        max=num3;
    if(max<num4)
        max=num4;
    if(min>num1)
        min=num1;
    if(min>num2)
        min=num2;
    if(min>num3)
        min=num3;
    if(min>num4)
        min=num4;
    System.out.println("The maximum number is "+max);
    System.out.println("The minimum number is "+min);
 }}
Output:

java program that check number is positive or negitive or zero



Problem 07:
Write a program that check number is positive negative or zero.
Discripition:
If number is greater then zero the number is positive if number is lessthen zero number is negative if number is equal to zero number is zero.
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
   System.out.println("Enter the  number");
    int num1=input.nextInt();
    if(num1>0)
         System.out.println("The number "+num1+" is positive");
   if(num1<0)
         System.out.println("The number "+num1+" is negitive");
   if(num1==0)
         System.out.println("The number "+num1+" is Zero");
 }}
Output:

jav aprogram find maximum number taking three number from user



Problem 06:
Write a program that take three numbers from user and find maximum number
Discripition:
First compare 1st number with 2nd  number then 1st with 3rd and then 2nd with 3rd
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
   System.out.println("Enter the frist  number");
    int num1=input.nextInt();
    System.out.println("Enter the Second  number");
    int num2=input.nextInt();
  System.out.println("Enter the Second  number");
    int num3=input.nextInt();
   if((num1>num2)&&(num1>num3))
        System.out.println("The maximum number is "+num1);
   if((num2>num1)&&(num2>num3))
        System.out.println("The maximum number is "+num2);
   if((num3>num2)&&(num3>num1))
         System.out.println("The maximum number is "+num3);
 }}
Output: