Write a program that inputs two double values and then calculates various results. Let the two double values be called a and b, in that order. Print out a to the power of b, the absolute value of a, the value of b rounded to the nearest integer, the smallest integer greater than or equal to a, and the bigger of either a or b. Comment your solution to this post.
top of page
bottom of page
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double a = sc.nextDouble(); Scanner sa = new Scanner(System.in); double b = sa.nextDouble(); System.out.println(); double number1 = a*b; System.out.println(number1); double number2 = Math.round(a); System.out.println(number2); double number3 = Math.round(b); System.out.println(number3); double number4 = Math.min(a, b); System.out.println("The lowest number is " + number4); double number5 = Math.max(a, b); System.out.println("The highest number is " +number5); } }
class Main { public static void main(String[] args) { double a = 4.2; double b = 6.9; int x = 4; double the_power_of_b = Math.pow(b, 4); System.out.println(the_power_of_b); double the_absolute_value_of_a = Math.abs(a); System.out.println(the_absolute_value_of_a); double b_rounded = Math.round(b); System.out.println(b_rounded); double the_smallest_integer_greater_than_or_equal_to_a = Math.ceil(a); System.out.println(the_smallest_integer_greater_than_or_equal_to_a); double the_bigger_of_either_a_or_b = Math.max(a, b); System.out.println(the_bigger_of_either_a_or_b); } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Scanner sc_2 = new Scanner(System.in); System.out.println("First number:"); double a = sc.nextDouble(); System.out.println("Second number:"); double b = sc_2.nextDouble(); double one = Math.pow(a,b); double two = Math.abs(a); double three = Math.round(b); double four = Math.ceil(a); double five = Math.max(a,b); System.out.println("Answer one: "+ one); System.out.println("Answer two: "+ two); System.out.println("Answer three: "+ three); System.out.println("Answer four: "+ four); System.out.println("Answer five: "+ five); } }
class Main { public static void main(String[] args) { double a = 3.7; double b = 2.3; System.out.println("a to the power of b is "+ Math.pow(a, b)); System.out.println("The absolute value of a is "+Math.abs(a)); System.out.println("b rounded is "+Math.round(b)); System.out.println("the smallest integer greater than or equal to a "+Math.ceil(a)); System.out.println("The bigger of the 2 numbers is "+Math.max(a, b)); } }
class Main { public static void main(String[] args) { double a = 1.2; double b = 2.6; int x = 4; double problem_1 = Math.pow(b, 4); System.out.println(problem_1); double problem_2 = Math.abs(a); System.out.println(problem_2); double problem_3 = Math.round(b); System.out.println(problem_3); } }
class Main { public static void main(String[] args) { double a = 2.3; double b = 7.6; int x = 2; double problem_1 = Math.pow(b, 2); System.out.println(problem_1); double problem_2 = Math.abs(a); System.out.println(problem_2); double problem_3 = Math.round(b); System.out.println(problem_3); double problem_4 = Math.ceil(a); System.out.println(problem_4); double problem_5 = Math.max(a, b); System.out.println(problem_5); } }