Write a Java-program to print division of two numbers
Program
public class Main
{
public static void main(String args[])
{
int x=10,y=2,z;
z=x/y;
System.out.println("Division is "+(z));
}
}
Output:
Division is 5
Using CommandLine Arguments
public class Main
{
public static void main(String args[])
{
int x,y,z;
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]);
z=x/y;
System.out.println("Division is "+(z));
}
}
Output:
Division is 5
Using Scanner Class
import java.util.*;
public class Main
{
public static void main(String args[])
{
int x,y,z;
Scanner s=new Scanner(System.in);
System.out.println("Enter x,y values");
x=s.nextInt();
y=s.nextInt();
z=x/y;
System.out.println("Division is "+(z));
}
}
Output:
Enter x,y values
10
2
Division is 5
More Questions
9 . Write a Java-program to print division of two numbers
10 . Write a Java-program to print modular division of two numbers
11 . Write a java-program to print swaping of two numbers with using third variable
12 . Write a Java-program to print swaping of two numbers without using third variable
13 . Write a java-program to print relation of two numbers
14 . Write a Java-program to print logical operators program using &&, || ,!
15 . Write a Java-program to print bitwise AND operation
16 . Write a Java-program to print bitwise OR operation
17 . Write a Java-program to print bitwise CAP operation
18 . Write a Java-program to print bitwise NEGATION operation
19 . Write a Java-program to print bitwise LEFT SHIFT operation