import java.util.Scanner;
public class estimateMath {
public static int estimateAdd(int num1, int num2) {
final int rounded1 = (int)(Math.round((double)num1 / 10))* 10;
final int rounded2 = (int)(Math.round((double)num2 / 10))* 10;
return rounded1 + rounded2;
}
public static int estimateSubtract(int num1, int num2) {
final int rounded1 = (int)(Math.round((double)num1 / 10))* 10;
final int rounded2 = (int)(Math.round((double)num2 / 10))* 10;
return rounded1 - rounded2;
}
}
import java.util.Scanner;
class lab7ex1 {
public static void main (String[] args) {
Scanner keyboard = new Scanner(System.in);
int absoluteOne;
int absoluteTwo;
int answer;
System.out.print(" Enter first number");
absoluteOne = keyboard.nextInt();
System.out.println();
System.out.print(" Enter second number");
absoluteTwo = keyboard.nextInt();
System.out.println();
while( (absoluteOne !=0) && (absoluteTwo !=0)){
answer = absolute(absoluteOne, absoluteTwo);
System.out.println("This number has the larger absolute value: " + answer);
System.out.println();
System.out.print(" Enter first number");
absoluteOne = keyboard.nextInt();
System.out.println();
System.out.print(" Enter second number");
absoluteTwo = keyboard.nextInt();
System.out.println();
}
}
public static int absolute (int parameter1 , int parameter2) {
int answer;
parameter1 = Math.abs(parameter1);
parameter2 = Math.abs(parameter2);
answer = Math.max(parameter1, parameter2);
return answer;
}
}
import java.util.Scanner;
public class lab7ex2 {
public static void main (String [] args) {
final Scanner keyboard = new Scanner(System.in);
int number1;
int number2;
do {
System.out.println("enter first integers:");
number1 = keyboard.nextInt();
System.out.println("enter second integers:");
number2 = keyboard.nextInt();
if (number1 == 0 && number2 == 0) {
System.out.println("Thank you");
} else {
System.out.println("The estimated Sum: " + estimateMath.estimateAdd(number1, number2));
System.out.println("The estimated difference: " + estimateMath.estimateSubtract(number1, number2));
}
} while ((number1 !=0) && (number2 !=0));
}
}
import java.util.*;
class lab7ex3 {
public static void main(String [] args) {
int dog = 12;
int cat = 9;
int mouse = 5;
int bird = 8;
swapit (mouse,bird);
System.out.println(swapit(dog,cat));
System.out.println(swapit(dog,mouse));
System.out.println(bird);
}
public static int swapit(int bug, int dog) {
int bird = bug + dog;
dog = dog + 2;
System.out.println(dog);
return bird;
}
}
http://erdoganakbiyik.blogspot.com/
https://www.youtube.com/channel/UCDsUnmBfVdEPkcC8FlzPKcg
No comments:
Post a Comment