menu
bartleby
search
close search
Hit Return to see all results

PART A. Write a program Is Divisible that reads two integers from the user and determines if one is divisible bythe other. Here are several examples:Enter two integers, I'll check if one is divisible by the other: 9 49 and 4 are not divisibleEnter two integers, I'll check if one is divisible by the other: 15 515 is divisible by 5Enter two integers, I'l1 check if one is divisible by the other: 5 1515 is divisible by 5

Question

/////////////

////////////

////////////

the language used is java

PART A. Write a program Is Divisible that reads two integers from the user and determines if one is divisible by
the other. Here are several examples:
Enter two integers, I'll check if one is divisible by the other: 9 4
9 and 4 are not divisible
Enter two integers, I'll check if one is divisible by the other: 15 5
15 is divisible by 5
Enter two integers, I'l1 check if one is divisible by the other: 5 15
15 is divisible by 5
help_outline

Image Transcriptionclose

PART A. Write a program Is Divisible that reads two integers from the user and determines if one is divisible by the other. Here are several examples: Enter two integers, I'll check if one is divisible by the other: 9 4 9 and 4 are not divisible Enter two integers, I'll check if one is divisible by the other: 15 5 15 is divisible by 5 Enter two integers, I'l1 check if one is divisible by the other: 5 15 15 is divisible by 5

fullscreen
check_circleAnswer
Step 1

Program code #1:

//import the required header files
import java.util.Scanner;
//define main class
class Main
//define main () method
public static void main(String[] args)
//declare require variables
int n1,n2,t;
//create an object of Scanner class
new Scanner(System.in);
Scanner s
//asking for the input
System.out.print("Enter two integers, i'll check if
one is divisible by other:");
//reading inputs
s. nextInt ()
s.nextInt()
n1
=
n2
help_outline

Image Transcriptionclose

//import the required header files import java.util.Scanner; //define main class class Main //define main () method public static void main(String[] args) //declare require variables int n1,n2,t; //create an object of Scanner class new Scanner(System.in); Scanner s //asking for the input System.out.print("Enter two integers, i'll check if one is divisible by other:"); //reading inputs s. nextInt () s.nextInt() n1 = n2

fullscreen
Step 2

Program code #2:

//if n2 is greater than n1 exchange the values
if(n2>n1)
{
/using a temp variable for exchanging the values
t-n1
n1-n2;
n2=t;
}
//checking whether n1 is divisible by n2
if (n1 % n2
{
//print if n1 is visible by n2
System.out.println(n1+" is divisible by "+n2);
}
else
{
//print if n1 is not visible by n2
System.out.println(n1+" and "+n2+" are not
divisible");
}
}
}
help_outline

Image Transcriptionclose

//if n2 is greater than n1 exchange the values if(n2>n1) { /using a temp variable for exchanging the values t-n1 n1-n2; n2=t; } //checking whether n1 is divisible by n2 if (n1 % n2 { //print if n1 is visible by n2 System.out.println(n1+" is divisible by "+n2); } else { //print if n1 is not visible by n2 System.out.println(n1+" and "+n2+" are not divisible"); } } }

fullscreen
Step 3

Output #1:

...
Enter two integers, i'll check if one is divisible by other:9 4
9 and 4 are not divisible
help_outline

Image Transcriptionclose

Enter two integers, i'll check if one is divisible by other:9 4 9 and 4 are not divisible

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: I need ERD Model Arrow Electronics is a consumer electronics retailer operating in the United States...

A: The 8 entities are indicated below with only their unqiue identifier (bold) and one or more other at...

question_answer

Q: In JavaScript, how can you validate a user’s input to make sure it is both a number and between 20 a...

A: JavaScriptitis a web programing language.it is a cross- platform language.Its code is integrated wit...

question_answer

Q: Consider the languages below. For each, make a conjecture whether or not it is regular. Then prove y...

A: The given language L = {anbl : n/l is an integer} is not regular language because a DFA cannot be co...

question_answer

Q: Please write Lisp code for the following problem. Consider the list:((name (number1 nation)) (MusicP...

A: Instructions to create a function to access the MovieTixHighPrices value using car and cdr:The funct...

question_answer

Q: Write a program in eclipse called ListEvenNumbers which prints the even numbers from 20 to 30 (inclu...

A: Writing a program to prints the even numbers from 20 to 30 (including 30). 

question_answer

Q: Construct an unambiguous grammar equivalent to the grammar in  S→AB|aaaB, A→a|Aa, B→b.

A: Solution: Construct an unambiguous grammar to grammar.Given that,S -> AB|aaaBA -> a|AaB -> ...

question_answer

Q: This is for python For this assignment, you will write a program to simulate a payroll application. ...

A: Instruction for the given program:Add the given Node class in the python file Node.py.Add the given ...

question_answer

Q: I have a Python question and I cannot seem to figure out how to answer this problem exactly (I've at...

A: Hey..To print the power of 2 you have to use a  power function  "pow(2,N) " .It is inbuild function ...

question_answer

Q: You are not required to execute the queries. However, your syntax must by accurate.You must give at ...

A: Hey, since there are multiple sub-part questions posted, we will answer first three questions. If yo...

Sorry about that. What wasn’t helpful?