0% found this document useful (0 votes)
9 views5 pages

Computer 1

The document contains code snippets for four Java programs: 1) multiplying two float numbers, 2) swapping two integers using a third variable, 3) swapping two integers without a third variable, 4) checking if an integer is even or odd.

Uploaded by

riddhimashetty28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Computer 1

The document contains code snippets for four Java programs: 1) multiplying two float numbers, 2) swapping two integers using a third variable, 3) swapping two integers without a third variable, 4) checking if an integer is even or odd.

Uploaded by

riddhimashetty28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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