You are on page 1of 5

ASSIGNMENT-2

WRITE A PROGRAM TO ACCEPT TWO FLOAT NO.S FROM USERS AND


DISPLAY THE OUTPUT AFTER MULTIPLYING IT

import java.util.Scanner;

class floa

public static void main(String agrs[])

Scanner sc=new Scanner(System.in);

float a,b;

System.out.println("Enter value for a");

a=sc.nextFloat();

System.out.println("Enter value for b");

b=sc.nextFloat();

Float mul=a*b;

System.out.println("The mul is:"+mul);

}
WRITE A PROGRAM TO SWAP TWO NO.S USING THIRD VARIABLE

import java.util.Scanner;

class swapusing

public static void main(String agrs[])

Scanner sc=new Scanner(System.in);

int c;

System.out.println("Enter the first no.");

int a=sc.nextInt();

System.out.println("Enter the second no.");

int b=sc.nextInt();

c=a;

a=b;

b=c;

System.out.println("The swapped value of a is:"+a);

System.out.println("The swapped value of b is:"+b);

}
WRITE A PROGRAM TO SWAP TWO NO.S W/O USING THIRD VARIABLE

import java.util.Scanner;

class swap

public static void main(String agrs[])

Scanner sc=new Scanner(System.in);

int a,b;

System.out.println("Enter the first no.");

a=sc.nextInt();

System.out.println("Enter the second no.");

b=sc.nextInt();

a=a+b;

b=a-b;

a=a-b;

System.out.println("The swapped value of a is:"+a);

System.out.println("The swapped value of b is:"+b);

}
}

WRITE A PROGRAM TO CHECK WHETHER ENTERED NO. IS EVEN OR ODD

import java.util.Scanner;

class LOGIC

public static void main(String agrs[])

Scanner sc=new Scanner(System.in);

System.out.println("Use please enter a digit");

int a=sc.nextInt();

if(a%2==0)

System.out.println("Even no. is entered");

else

System.out.println("Odd no. is entered");

You might also like