0% found this document useful (0 votes)
4 views3 pages

Java Methods for Number Operations

java homework

Uploaded by

alondana100
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java Methods for Number Operations

java homework

Uploaded by

alondana100
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

Random;
import [Link];

public class Main {

static Scanner scanner = new Scanner([Link]);


static Random random = new Random();

public static void main(String[] args) {


/*
//P184 Q5
[Link]("enter the two numbers: ");
randomNum2([Link](), [Link]());

*/
/*
//P184 Q6
EvenCheck(22);

int largest = 0;
int current;
int num = 0;
int bestNum = 0;
while(num != -1){
[Link]("enter a number: ");
[Link]("enter -1 when you are done: ");
num = [Link]();
current = EvenCheck(num);
if(current > largest){
largest = current;
bestNum = num;
}
}
[Link]("the number with the mose even digits
is: " + bestNum);

*/
/*
//P184 Q7
[Link]("how many people are coming? ");
int people = [Link]();
[Link]("how much space is in the bus: ");
int bus = [Link]();
[Link]("how much space is in a table: ");
int table = [Link]();
[Link]("how much space is in a boat: ");
int boat = [Link]();
items(people,bus,table,boat);

*/

//P184 Q8
commonDenominator(9,18);

}
//P184 Q5
public static void randomNum1(int num1, int num2){
int random = (int)([Link]() * num2) + num1;
[Link](random + " ");
}
public static void randomNum2(int num1, int num2){
if(num1 != -999 && num2 != -999){
for (int i = 0; i < 5; i++) {
randomNum1(num1,num2);
}
}
}

//P184 Q6
public static int EvenCheck(int num){

int counter = 0;
int temp = num;
if(num == 0){
counter = 1;
}

while(temp > 0){

if(temp % 10 % 2 == 0){
counter++;
}
temp/=10;
}
return counter;
}
//P184 Q7
public static void items(int numPeople, int busSpace, int
tableSpace, int boatSpace){
int busNum = numPeople/busSpace;
int tableNum = numPeople/tableSpace;
int boatNum = numPeople/boatSpace;

[Link]("you will need %d busses, %d tables and


%d boats", busNum, tableNum, boatNum);
}
//P184 Q8
public static int commonDenominator(int num1, int num2){
int smaller = [Link](num1, num2);
for (int i = 2; i < smaller + 2; i++) {
if(num1 % i == 0 && num2 % i == 0){
[Link]("the smallest common
denominator is: " + i);
return i;
}

}
return -1;
}
}

You might also like