Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.Math.*;
- public class Main {
- public static Scanner reader = new Scanner(System.in);
- public static void Q4() {
- System.out.println("Q4");
- System.out.println("Enter 2 sides of a right angle triangle: ");
- int n1 = reader.nextInt();
- int n2 = reader.nextInt();
- System.out.println("hypotenuse: " + Math.sqrt(Math.pow(n1, 2) + Math.pow(n2, 2)));
- }
- public static void Q5(){
- System.out.println("\nQ5");
- double ran1 = Math.random();
- double ran2 = Math.random();
- double ran3 = Math.random();
- System.out.println("the average of the numbers: " + (ran1 + ran2 + ran3) / 3);
- }
- public static void Q6(){
- System.out.println("\nQ6");
- System.out.println("Enter 3 sides of triangle: ");
- int a = reader.nextInt();
- int b = reader.nextInt();
- int c = reader.nextInt();
- double p = (a + b + c) / 2.0;
- System.out.println("area: " + Math.sqrt(p * (p - a) * (p - b) * (p - c)));
- System.out.println("circumference: " + a + b + c);
- }
- public static void Q7(){
- System.out.println("\nQ7");
- System.out.println("Insert money: ");
- double num = reader.nextDouble();
- System.out.println("shekels: " + Math.floor(num) + ", pennies: " + (num * 100) % 100 / 100);
- }
- public static void Q8(){
- System.out.println("\nQ8");
- System.out.println("Enter triple digits number: ");
- int num = reader.nextInt();
- if ((Math.pow(num % 10, 3) + Math.pow((num / 10) % 10, 3) + Math.pow(num / 100, 3)) == num)
- System.out.println("a triple number");
- else
- System.out.println("not a triple number");
- }
- public static void Q9(){
- System.out.println("\nQ9");
- System.out.println("Enter a grade: ");
- double grade = reader.nextDouble();
- System.out.println("grade: " + Math.round(grade) + ", the saved part: " + (grade * 10) % 10 / 10);
- }
- public static void Q10(){
- System.out.println("\nQ10");
- System.out.println("Enter a number with 3 digits after the dot: ");
- double num = reader.nextDouble();
- System.out.println("rounded number: " + (Math.round(num * 10) / 10.0));
- }
- public static void Q11(){
- System.out.println("\nQ11");
- System.out.println("Enter a number: ");
- int num = reader.nextInt();
- System.out.println("result: " + (num/Math.abs(num)));
- }
- public static void Q13(){
- System.out.println("\nQ13");
- System.out.println("Enter a number: ");
- int guess = reader.nextInt();
- int roll = (int)(Math.random()*6);
- System.out.println("your guess: " + guess + ", the roll: " + roll);
- if (roll == guess)
- System.out.println("you were right!");
- else
- System.out.println("you missed by " + Math.abs(guess - roll));
- }
- public static void main(String[] args) {
- Q4(); Q5(); Q6(); Q7(); Q8(); Q9(); Q10(); Q11(); Q13();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement