Advertisement
StefanTobler

Lesson 6 Activity 1

Sep 11th, 2016
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /*
  2.  * Lesson 6 Coding Activity Question 1
  3.  
  4. double x = (11+4)/2
  5.  
  6.  * What answer do you get? The answer is imprecise!
  7.  *
  8.  * Write a Java program that precisely calculates the average
  9.  * between two integers that input from the keyboard, and prints
  10.  * the answer to the screen. The average must include the integer
  11.  * and decimal portions of the calculation.
  12.  *
  13.  * Sample Run:
  14.  
  15. Please enter two integers:
  16. 4
  17. 11
  18.  
  19. The average is: 7.5
  20.  
  21. */
  22.  
  23. import java.util.Scanner;
  24. import java.lang.Math;
  25.  
  26. class Lesson_6_Activity_One {
  27.     public static void main(String[] args) {
  28.      
  29.       Scanner scan = new Scanner(System.in);
  30.       System.out.println("Please enter two integers: ");
  31.       int x = scan.nextInt();
  32.       int y = scan.nextInt();
  33.      
  34.       System.out.println("The average is: " + ((double)(x + y)/2));
  35.  
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement