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

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 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 Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz