Programming Examples

Java program to input 2 integer number and divide the larger number with smaller number


Write a program to pass 2 integer numbers as parameters. If either of the two numbers is 0, display invalid entry and the program should end, if it is valid entry, divide the larger number with the smaller number and display the result.

Solution

class Divide
{
	public static void main(int a, int b)
	{
		float c;
		if (a==0 || b==0)
			System.out.println(“Invalid entry”);
		else
		{
			if(a>b)
				c=(float)a/b;
			else
				c=(float)b/a;
			System.out.println(“Quotient:”+c);
		}
	}
}
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad