# Field Manual for Hackers

## Java Write a program that inputs a pair of number num1 and num2 and divide the larger of the two by smaller.

Write a program that inputs a pair of number num1 and num2 and divide the larger of the two by smaller.
Note: it will first be necessary to test for a zero value, since divide by zero will cause program to halt immediately.

1. import java.util.Scanner;

class Test{

public static void main(String ar[])
{

Scanner sc=new Scanner(System.in);
double num1,num2,divide;
System.out.println("Enter First Number");
num1=sc.nextDouble();
System.out.println("Enter Second Number");
num2=sc.nextDouble();
if(num1==0 || num2==0)
{
System.out.println("0 is not allowed.");
}
else
{
if(num1>num2){divide=num1/num2;System.out.println(num1+" / "+num2+" = "+divide);}
else{divide=num2/num1;System.out.println(num2+" / "+num1+" = "+divide);}
}

}

}

2. import java.util.Scanner;
class Divide
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter two numbers");
double NUM1=sc.nextDouble();
double NUM2=sc.nextDouble();
double num;
if(NUM1==0||NUM2==0)
{
System.out.println("0 is not allowed");
}
if(NUM1>NUM2)
{num=NUM1/NUM2;
System.out.println("division of two numbers is"+num);
}
else
{
num=NUM2/NUM1;
System.out.println("division of two numbers is"+num);
}
}
}

3. import java.util.Scanner;
class largerSmaller
{
public static void main(String ar[])
{double num1,num2;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the num1");
num1=scan.nextDouble();
System.out.println("Enter the num2");
num2=scan.nextDouble();
if(num1>num2)
{System.out.println("The result="+(num1/num2));}

else{System.out.println("The result="+(num2/num1));}
}
}

4. import java.util.Scanner;

class Test
{

public static void main(String ar[])
{

Double a,b,r;
System.out.print("Enter first number: ");
Scanner obj=new Scanner(System.in);
a=obj.nextDouble();
System.out.print("Enter second number: ");
b=obj.nextDouble();
if(a<b)
{ if(a==0)
System.out.println("Division not possible");
else
{
r=b/a;
System.out.println("The result is: "+r);
}
}
else
{ if(b==0)
System.out.println("Division not possible");
else
{
r=a/b;
System.out.println("The result is: "+r);
}
}

}
}

5. import java.util.Scanner;

class dividenum
{
public static void main(String ar[])
{
Scanner div = new Scanner(System.in);
double num1,num2,result;
System.out.println("Enter the first number");
num1 = div.nextDouble();
System.out.println("Enter the second number");
num2 = div.nextDouble();
if(num1 == 0 || num2 == 0)
System.out.println("0 cannot be entered");
{
if(num1>num2)
result = num1/num2;
else
result = num2/num1;
}
System.out.println(" the resultant is : " +result);
}
}

6. import java.util.*;
public class TwoNumber
{
public static void main(String args[])
{
double num1,num2,num;
System.out.println("Enter two number");
Scanner sc=new Scanner(System.in);
num1=sc.nextDouble();
num2=sc.nextDouble();
if(num1>num2)
{
num=num1/num2;
System.out.println(num);
}
else
{
num=num2/num1;
System.out.println(num);
}
}
}

7. import java.util.Scanner;
class Large{
public static void main(String ar[]){
Scanner obj=new Scanner(System.in);
int num1,num2;
System.out.println("enter the numbers");
num1=obj.nextInt();
num2=obj.nextInt();
if(num1==0||num2==0)
System.out.println("commands not possible as division by zero is not allowed");
else if(num1>num2)

System.out.println(num1/num2);
else
System.out.println(num2/num1);
}

}

8. import java.util.Scanner;
class Divide{
public static void main(String ar[]){
int a,b;
double d=0;
Scanner scan=new Scanner(System.in);
System.out.println("Enter the numbers");
a=scan.nextInt();
b=scan.nextInt();

if(a==0||b==0){
System.out.println("can't apply 0");
}

else if(a>b){
d=(a/b);
}

else if (a<b){
d=(b/a);
}
}
}

9. import java.util.Scanner;

class Divide{

public static void main(String ar[]){

int num1;
int num2;
double div;

Scanner scan=new Scanner(System.in);
System.out.println("Enter first number:");
num1=scan.nextInt();

System.out.println("Enter second number:");
num2=scan.nextInt();

if(num1==0||num2==0){
System.out.println("The number should be other than 0");
}
else if(num1>num2){
div=num1/num2;
}
else{
div=num1/num2;
}

}
}

10. import java.util.Scanner;
class Number{
public static void main(String ar[]){
Scanner s=new Scanner(System.in);
double a,b;
System.out.println("enter first number");
a=s.nextDouble();
System.out.println("enter second number");
b=s.nextDouble();
if(a==0||b==0)
{System.out.println("exit");
}
else if(a>b)
{ System.out.println( a/b );
}
else if(b>a)
{ System.out.println( b/a );
}
}
}

11. package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextClock;
import android.widget.TextView;

public class Division extends Activity {

int num1,num2,div;
Button btdiv;
EditText etdiv,etdiv2;
TextView tvdiv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
btdiv=findViewById(R.id.btDivision);
tvdiv=findViewById(R.id.tvDivision);
etdiv=findViewById(R.id.etDivision);
etdiv2=findViewById(R.id.etDivision2);

btdiv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1=Integer.parseInt(etdiv.getText().toString());
num2=Integer.parseInt(etdiv2.getText().toString());

if (num1>num2){

div=num1/num2;

tvdiv.setText("num1/num2="+div);
}else {

div=num2/num1;

tvdiv.setText("num2/num1="+div);

}
}
});
}
}