Rawad Fares Rawad Fares - 3 years ago 179
Java Question

How should I solve this?????dsf

1)Write a program that reads three integers from the user, and prints them in an ascending order.

2)your cellphone rings. print "answer" if you should answer it, otherwise print "decline". normally you answer, except in the morning, you only answer if it is your mom calling. in all cases if you are asleep you dont answer. given 3 Booleans isMorning, isMom, isAsleep (respectively) check if you should answer or not.

3)you are driving a little too fast, and a police officer stops you. if your speed is 60 or less, the officer will not fine you. if your speed is between 61 and 80 inclusive, you get a 50$ ticket. if your speed is 81 or more, you can get a 100$ ticket. unless its your birthday-- on that day, your speed can be 5 higher in all cases. write a program that reads an integer speed and a Boolean isBirthday and prints the value of speeding ticket or "no ticket" if you should not be fined

Answer Source

1)

import java.util.Scanner;

public class App {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("Enter 3 integers");
        System.out.print("a: ");
        int a = input.nextInt();
        System.out.print("b: ");
        int b = input.nextInt();
        System.out.print("c: ");
        int c = input.nextInt();

        if (a > b) {
            if (a > c) {
                if (c > b) {
                    System.out.println(b);
                    System.out.println(c);
                    System.out.println(a);
                } else {
                    System.out.println(c);
                    System.out.println(b);
                    System.out.println(a);
                }
            } else {
                System.out.println(b);
                System.out.println(a);
                System.out.println(c);
            }
        } else {
            if (a > c) {
                System.out.println(c);
                System.out.println(a);
                System.out.println(b);
            } else {
                if (c > b) {
                    System.out.println(a);
                    System.out.println(b);
                    System.out.println(c);
                } else {
                    System.out.println(a);
                    System.out.println(c);
                    System.out.println(b);
                }
            }

        }
    }
}

2)

import java.util.Scanner;

public class App {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Phone ringing");
        System.out.print("Are you asleep? "); 
        //Of course you are -_-
        boolean isAsleep = input.nextBoolean();
        System.out.print("Is this morning? ");
        boolean isMorning = input.nextBoolean();
        System.out.print("Is that your mom calling? ");
        boolean isMom = input.nextBoolean();

        if(isMom && !isAsleep){
            System.out.println("Answered");
        }else if(!isMorning && !isAsleep){
            System.out.println("Answered");
        }
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download