Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Create a small program that asks the user for two integers and then outputs t

ID: 3599130 • Letter: 1

Question

1) Create a small program that asks the user for two integers and then outputs the larger absolute value of the two numbers. Your program should have a static method that is sent two integers as parameters and returns an integer that has the larger magnitude. The method should do only this, the rest is done in the main. If you are not creating a method, you will not get any credit for this problem. Inside the main you should also have a loop that allows you to repeat the query until 0 0 are given as the inputs. writ in java.

Explanation / Answer

import java.util.*;

import java.lang.*;

import java.io.*;

class Largenum

{

public static void main(String args[]) throws java.lang.Exception

{

int num1, num2, larger;

Scanner scan = new Scanner(System.in); //create scanner object

while(true) //continues indefinitely until break is encountered

{

System.out.print(" Enter Two Numbers : ");

num1 = scan.nextInt(); //scan numbers

num2 = scan.nextInt();

if(num1!=0&&num2!=0) // if both the inputs are zeros then it repeats the query

{

break;

}

larger=returnlarge(num1,num2); //sends the two numbers as parameters to the method

System.out.print("Largest of Two Numbers is " +larger); //prints larger number

  

  

}

}

public static int returnlarge(int a,int b) //static method

{

int c;

c=(a>b)?a:b; //using conditional operator to get largest number

return c; // returns larger value

}

}