Java program for division of 2 number

Java program for division of 2 number
or
Java program to find Quotient between 2 number.

Program:-
import java.util.Scanner;

class div{
public static void main(String arg[]){
float num1, num2;
double ans;
Scanner data = new Scanner(System.in);
// Reading 1st number
System.out.println("Enter 1st number");
num1 = data.nextInt();
//Reading 1st number
System.out.println("Enter 2nd number");
num2 = data.nextInt();
// checking divisor nonzero number
if(num2!=0)
{
// Finding Quotient
ans=num1/num2;
//Displaying Quotient
System.out.println("Quotient:"+ans);
}
else
System.out.println("Divisor should be nonzero number");
}
}


Output 1:-

Enter 1st number
14
Enter 2nd number
2
Quotient:7.0


Output 2:-

Enter 1st number
28
Enter 2nd number
0
Divisor should be nonzero number


Output 3:-

Enter 1st number
258
Enter 2nd number
587
Quotient:0.43952301144599915

Output 4:-

Enter 1st number
-25
Enter 2nd number
23
Quotient:-1.08695650100708

Output 5:-

Enter 1st number
-29
Enter 2nd number
-58
Quotient:0.5

Output 6:-

Enter 1st number
25
Enter 2nd number
-45
Quotient:-0.5555555820465088





Learn Java:-
Java codes

Java Programs:-
List of Java Programs

2 Comments

  1. thanks for this wonderful blog that you've posted on this page.great effort and attainment of such a great information very much interest about your blog.keep it up.
    Java Training Institute in Chennai

    ReplyDelete
  2. thanks for this wonderful blog that you've posted on this page.great effort and attainment of such a great information very much interest about your blog.keep it up.
    Java Training in Chennai

    ReplyDelete

Add your comments here

Back to Top