Advertisement
Shahar_Goldenberg

p106_107

Nov 7th, 2022 (edited)
1,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.Math.*;
  3. public class Main {
  4.     public static Scanner reader = new Scanner(System.in);
  5.     public static void Q4() {
  6.         System.out.println("Q4");
  7.         System.out.println("Enter 2 sides of a right angle triangle: ");
  8.         int n1 = reader.nextInt();
  9.         int n2 = reader.nextInt();
  10.         System.out.println("hypotenuse: " + Math.sqrt(Math.pow(n1, 2) + Math.pow(n2, 2)));
  11.     }
  12.     public static void Q5(){
  13.         System.out.println("\nQ5");
  14.         double ran1 = Math.random();
  15.         double ran2 = Math.random();
  16.         double ran3 = Math.random();
  17.         System.out.println("the average of the numbers: " + (ran1 + ran2 + ran3) / 3);
  18.     }
  19.     public static void Q6(){
  20.         System.out.println("\nQ6");
  21.         System.out.println("Enter 3 sides of triangle: ");
  22.         int a = reader.nextInt();
  23.         int b = reader.nextInt();
  24.         int c = reader.nextInt();
  25.         double p = (a + b + c) / 2.0;
  26.         System.out.println("area: " + Math.sqrt(p * (p - a) * (p - b) * (p - c)));
  27.         System.out.println("circumference: " + a + b + c);
  28.     }
  29.     public static void Q7(){
  30.         System.out.println("\nQ7");
  31.         System.out.println("Insert money: ");
  32.         double num = reader.nextDouble();
  33.         System.out.println("shekels: " + Math.floor(num) + ", pennies: " + (num * 100) % 100 / 100);
  34.     }
  35.     public static void Q8(){
  36.         System.out.println("\nQ8");
  37.         System.out.println("Enter triple digits number: ");
  38.         int num = reader.nextInt();
  39.         if ((Math.pow(num % 10, 3) + Math.pow((num / 10) % 10, 3) + Math.pow(num / 100, 3)) == num)
  40.             System.out.println("a triple number");
  41.         else
  42.             System.out.println("not a triple number");
  43.     }
  44.     public static void Q9(){
  45.         System.out.println("\nQ9");
  46.         System.out.println("Enter a grade: ");
  47.         double grade = reader.nextDouble();
  48.         System.out.println("grade: " + Math.round(grade) + ", the saved part: " + (grade * 10) % 10 / 10);
  49.     }
  50.     public static void Q10(){
  51.         System.out.println("\nQ10");
  52.         System.out.println("Enter a number with 3 digits after the dot: ");
  53.         double num = reader.nextDouble();
  54.         System.out.println("rounded number: " + (Math.round(num * 10) / 10.0));
  55.     }
  56.     public static void Q11(){
  57.         System.out.println("\nQ11");
  58.         System.out.println("Enter a number: ");
  59.         int num = reader.nextInt();
  60.         System.out.println("result: " + (num/Math.abs(num)));
  61.     }
  62.     public static void Q13(){
  63.         System.out.println("\nQ13");
  64.         System.out.println("Enter a number: ");
  65.         int guess = reader.nextInt();
  66.         int roll = (int)(Math.random()*6);
  67.         System.out.println("your guess: " + guess + ", the roll: " + roll);
  68.         if (roll == guess)
  69.             System.out.println("you were right!");
  70.         else
  71.             System.out.println("you missed by " + Math.abs(guess - roll));
  72.     }
  73.  
  74.     public static void main(String[] args) {
  75.         Q4(); Q5(); Q6(); Q7(); Q8(); Q9(); Q10(); Q11(); Q13();
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement