URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Even Numbers) 1059:
Even Numbers is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @E-mail : [email protected]
 * @Date : Oct 14, 2016
 * @Time : 7:13:58 PM
 */
public class Uri1059 {

    public static void main(String[] args) {
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                System.out.println(i);
            }
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Month) 1052 Solution in Java

URI Problem (Month) 1052:
Month is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 14, 2016
 * @Time   : 6:59:52 PM
 */
public class Uri1052 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String months[] = {"January","February","March","April","May","June",
            "July","August","September","October","November","December"};
        int month = sc.nextInt();
        if(month>=1 && month<=12){
            System.out.println(months[month-1]); 
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Taxes) 1051 Solution in Java

URI Problem (Taxes) 1051:
Taxes is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 6:03:24 PM
 */
public class Uri1051 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double salary, tax = 0;
        salary = sc.nextDouble();
        if (salary >= 0.0 && salary <= 2000.00) {
            System.out.println("Isento");
        } else if (salary >= 2000.01 && salary <= 3000.00) {
            tax += (salary - 2000.00) * 0.08;
            System.out.printf("R$ %.2f\n", tax);
        } else if (salary >= 3000.01 && salary <= 4500.00) {
            tax += 1000.00 * 0.08;
            tax += (salary - 3000) * 0.18;
            System.out.printf("R$ %.2f\n", tax);
        } else if (salary > 4500.00) {
            tax += 1000.00 * 0.08;
            tax += 1500.00 * 0.18;
            tax += (salary - 4500.00) * 0.28;
            System.out.printf("R$ %.2f\n", tax);
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (DDD) 1050 Solution in Java

URI Problem (DDD) 1050:
DDD is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 5:14:33 PM
 */
public class Uri1050 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        switch (number) {
            case 61:
                System.out.println("Brasilia");
                break;
            case 71:
                System.out.println("Salvador");
                break;
            case 11:
                System.out.println("Sao Paulo");
                break;
            case 21:
                System.out.println("Rio de Janeiro");
                break;
            case 32:
                System.out.println("Juiz de Fora");
                break;
            case 19:
                System.out.println("Campinas");
                break;
            case 27:
                System.out.println("Vitoria");
                break;
            case 31:
                System.out.println("Belo Horizonte");
                break;
            default:
                System.out.println("DDD nao cadastrado");
                break;
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Animal) 1049 Solution in Java

URI Problem (Animal) 1049:
Animal is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 14, 2016
 * @Time   : 4:21:29 PM
 */
public class Uri1049 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String v1,v2,v3;
        v1 = toLowerAndTrim(sc.next());
        v2 = toLowerAndTrim(sc.next());
        v3 = toLowerAndTrim(sc.next());
        if(v1.equalsIgnoreCase("vertebrado")){
            if(v2.equalsIgnoreCase("ave")){
                if(v3.equalsIgnoreCase("carnivoro")){
                    System.out.println("aguia");
                }else if(v3.equalsIgnoreCase("onivoro")){
                    System.out.println("pomba");
                }
            }else if(v2.equalsIgnoreCase("mamifero")){
                if(v3.equalsIgnoreCase("onivoro")){
                    System.out.println("homem");
                }else if(v3.equalsIgnoreCase("herbivoro")){
                    System.out.println("vaca");
                }
            }
        }else if(v1.equalsIgnoreCase("invertebrado")){
            if(v2.equalsIgnoreCase("inseto")){
                if(v3.equalsIgnoreCase("hematofago")){
                    System.out.println("pulga");
                }else if(v3.equalsIgnoreCase("herbivoro")){
                    System.out.println("lagarta");
                }
            }else if(v2.equalsIgnoreCase("anelideo")){
                if(v3.equalsIgnoreCase("hematofago")){
                    System.out.println("sanguessuga");
                }else if(v3.equalsIgnoreCase("onivoro")){
                    System.out.println("minhoca");
                }
            }
        }
    }

    private static String toLowerAndTrim(String next) {
        return next.trim().toLowerCase();
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Salary Increase) 1048 Solution in Java

URI Problem (Salary Increase) 1048:
Salary Increase is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 3:41:23 PM
 */
public class Uri1048 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double salary, new_salary, money_earned;
        int percentage;
        salary = sc.nextDouble();
        if (salary >= 0.00 && salary <= 400.00) {
            percentage = 15;
            calculation_and_print(salary, percentage);
        }else if (salary >= 400.01 && salary <= 800.00) {
            percentage = 12;
            calculation_and_print(salary, percentage);
        }else if (salary >= 800.01 && salary <= 1200.00) {
            percentage = 10;
            calculation_and_print(salary, percentage);
        }else if (salary >= 1200.01 && salary <= 2000.00) {
            percentage = 7;
            calculation_and_print(salary, percentage);
        }else if (salary > 2000.00) {
            percentage = 4;
            calculation_and_print(salary, percentage);
        }
    }

    private static void calculation_and_print(double salary, int percentage) {
        double money_earned;
        double new_salary;
        money_earned = salary * (percentage / 100.00);
        new_salary = salary + money_earned;
        System.out.printf("Novo salario: %.2f\n", new_salary);
        System.out.printf("Reajuste ganho: %.2f\n", money_earned);
        System.out.println("Em percentual: "+ percentage+" %");
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Game Time with Minutes) 1047 Solution in Java

URI Problem (Game Time with Minutes) 1047:
Game Time with Minutes is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 12, 2016
 * @Time : 2:31:23 PM
 */
public class Uri1047 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int start_hour, start_minute, end_hour, end_minute, hour = 0, minute = 0;
        start_hour = sc.nextInt();
        start_minute = sc.nextInt();
        end_hour = sc.nextInt();
        end_minute = sc.nextInt();
        if (start_hour >= 0 && start_hour <= 24 && end_hour >= 0
                && end_hour <= 24 && start_minute >= 0 && start_minute <= 60
                && end_minute >= 0 && end_minute <= 60) {
            if (end_minute > start_minute) {
                minute = end_minute - start_minute;
            } else if (end_minute < start_minute) {
                minute = end_minute - start_minute + 60;
                end_hour = end_hour - 1;
            }
            if (end_hour >= start_hour) {
                hour = end_hour - start_hour;
            } else if (end_hour < start_hour) {
                hour = end_hour - start_hour + 24;
            }
            if (hour == 0 && minute == 0) {
                hour = 24;
            }
        }
        System.out.println("O JOGO DUROU " + hour + " HORA(S) E " + minute + " MINUTO(S)");
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Game Time) 1046 Solution in Java

URI Problem (Game Time) 1046:
Game Time is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 12, 2016
 * @Time : 2:10:33 PM
 */
public class Uri1046 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int start, end, duration = 0;
        start = sc.nextInt();
        end = sc.nextInt();
        if (start <= 24 && end <= 24 && start >= 0 && end >= 0) {
            if (end > start) {
                duration = end - start;
            } else if (end < start || end == start) {
                duration = (end - start) + 24;
            }
            System.out.println("O JOGO DUROU "+duration+" HORA(S)");
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Triangle Types) 1045 Solution in Java

URI Problem (Triangle Types) 1045:
Triangle Types is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 11, 2016
 * @Time : 3:31:17 PM
 */
public class Uri1045 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a, b, c;
        a = sc.nextDouble();
        b = sc.nextDouble();
        c = sc.nextDouble();
        if (a > 0 && b > 0 && c > 0) {
            double abc[] = sortDecreasing(new double[]{a, b, c});
            a = abc[0];
            b = abc[1];
            c = abc[2];
            //if A ≥ B + C, write the message: NAO FORMA TRIANGULO
            if (a >= (b + c)) {
                System.out.println("NAO FORMA TRIANGULO");
            }
            //if A2 = B2 + C2, write the message: TRIANGULO RETANGULO
            else if ((a * a) == ((b * b) + (c * c))) {
                System.out.println("TRIANGULO RETANGULO");
            }
            //if A2 > B2 + C2, write the message: TRIANGULO OBTUSANGULO
            else if ((a * a) > ((b * b) + (c * c))) {
                System.out.println("TRIANGULO OBTUSANGULO");
            }
            //if A2 < B2 + C2, write the message: TRIANGULO ACUTANGULO
            else if ((a * a) < ((b * b) + (c * c))) {
                System.out.println("TRIANGULO ACUTANGULO");
            }
            
            //if the three sides are the same size, write the message: TRIANGULO EQUILATERO
            if (a == b && b == c  && c==a) {
                System.out.println("TRIANGULO EQUILATERO");
            }
            //if only two sides are the same and the third one is different, write the message: TRIANGULO ISOSCELES
            else if ((a == b && a != c) || (b == c && b != a) || (a == c && a != b)) {
                System.out.println("TRIANGULO ISOSCELES");
            }
        }
    }

    private static double[] sortDecreasing(double[] par) {

        for (int i = 0; i < par.length; i++) {
            for (int j = 0; j < par.length - 1; j++) {
                if (par[j] < par[j + 1]) {
                    double temp = par[j];
                    par[j] = par[j + 1];
                    par[j + 1] = temp;
                }

            }
        }
        return par;
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Multiples) 1044 Solution in Java

URI Problem (Multiples) 1044:
Multiples is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 10, 2016
 * @Time   : 11:01:05 PM
 */
public class Uri1044 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a,b;
        a = sc.nextInt();
        b = sc.nextInt();
        if(b%a==0 || a%b==0){
            System.out.println("Sao Multiplos");
        }else{
            System.out.println("Nao sao Multiplos");
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Triangle) 1043 Solution in Java

URI Problem (Triangle) 1043:
Triangle is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 10, 2016
 * @Time : 10:50:53 PM
 */
public class Uri1043 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a, b, c, perimeter, area_trapezium;
        a = sc.nextDouble();
        b = sc.nextDouble();
        c = sc.nextDouble();
        if ((a + b) > c && (b + c) > a && (c + a) > b) {
            perimeter = a + b + c;
            System.out.printf("Perimetro = %.1f\n", perimeter);
        } else {
            area_trapezium = ((a + b) / 2) * c;
            System.out.printf("Area = %.1f\n", area_trapezium);
        }
    }

}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Simple Sort) 1042 Solution in Java

URI Problem (Simple Sort) 1042:
Simple Sort is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 10, 2016
 * @Time   : 10:10:17 PM
 */
public class Uri1042 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a , b , c , t;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        int sort[]={a,b,c};
        int temp[]={a,b,c};
        Arrays.sort(sort);
        for (int i = 0; i < sort.length; i++) {
            System.out.println(sort[i]);
        }
        System.out.println();
        for (int i = 0; i < temp.length; i++) {
            System.out.println(temp[i]);
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Coordinates of a Point) 1041 Solution in Java

URI Problem (Coordinates of a Point) 1041:
Coordinates of a Point is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 10, 2016
 * @Time   : 9:56:05 PM
 */
public class Uri1041 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x,y;
        x = sc.nextDouble();
        y = sc.nextDouble();
        if(x!=0 && y==0){
            System.out.println("Eixo X");
        }else if(x==0 && y!=0){
            System.out.println("Eixo Y");
        }else if(x == 0 && y ==0){
            System.out.println("Origem");
        }else if(x>0 && y>0){
            System.out.println("Q1");
        }else if(x<0 && y>0){
            System.out.println("Q2");
        }else if(x<0 && y<0){
            System.out.println("Q3");
        }else if(x>0 && y<0){
            System.out.println("Q4");
        }else{
            
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Average 3) 1040 Solution in Java

URI Problem (Average 3) 1040:
Average 3 is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.text.DecimalFormat;
import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 10, 2016
 * @Time : 9:09:13 PM
 */
public class Uri1040 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double n1, n2, n3, n4, n5, average, recalculate;
        int a = 2, b = 3, c = 4, d = 1;
        n1 = sc.nextDouble();
        n2 = sc.nextDouble();
        n3 = sc.nextDouble();
        n4 = sc.nextDouble();
        average = toDouble(((n1 * a) + (n2 * b) + (n3 * c) + (n4 * d)) / (a + b + c + d));
        System.out.println("Media: " + average);
        if (average >= 7.0) {
            System.out.println("Aluno aprovado.");
        } else if (average < 5.0) {
            System.out.println("Aluno reprovado.");
        } else if(average >=5.00 && average <= 6.9){
            System.out.println("Aluno em exame.");
            n5 = sc.nextDouble();
            System.out.println("Nota do exame: " + n5);
            recalculate = toDouble((n5 + average) / 2);
            if (recalculate >= 5.0) {
                System.out.println("Aluno aprovado.");
            } else if (recalculate <= 4.9) {
                System.out.println("Aluno reprovado.");
            }
            System.out.println("Media final: " + recalculate);
        }

    }
    private static double toDouble(double x){
            DecimalFormat format = new DecimalFormat("#0.0");
            return Double.valueOf(format.format(x));
        }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Snack) 1038 Solution in Java

URI Problem (Snack) 1038:
Snack is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 10, 2016
 * @Time   : 1:47:37 AM
 */
public class Uri1038 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x,y;
        x = sc.nextInt();
        y = sc.nextInt();
        double price[] = {4.00,4.50,5.00,2.00,1.50};
        if(price.length >= x){
        System.out.printf("Total: R$ %.2f\n",price[x-1]*y);
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Interval) 1037 Solution in Java

URI Problem (Interval) 1037:
Interval is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 10, 2016
 * @Time : 1:36:06 AM
 */
public class Uri1037 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x = sc.nextDouble();
        if (x >= 0 && x <= 25) {
            System.out.println("Intervalo " + "[0,25]");
        } else if (x > 25 && x <= 50) {
            System.out.println("Intervalo " + "(25,50]");
        } else if (x > 50 && x <= 75) {
            System.out.println("Intervalo " + "(50,75]");
        } else if (x > 75 && x <= 100) {
            System.out.println("Intervalo " + "(75,100]");
        } else {
            System.out.println("Fora de intervalo");
        }
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Bhaskara’s Formula) 1036 Solution in Java

URI Problem (Bhaskara’s Formula) 1036:
Bhaskara’s Formula is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 10, 2016
 * @Time : 1:14:36 AM
 */
public class Uri1036 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double x = nonNegative(a, b, c);
        double y = nonZero(a);
        if (y != 0 && x >= 0) {
            double r1 = (-b+Math.sqrt(x))/y;
            double r2 = (-b-Math.sqrt(x))/y;
            System.out.printf("R1 = %.5f\n",r1);
            System.out.printf("R2 = %.5f\n",r2);
        } else {
            System.out.println("Impossivel calcular");
        }

    }

    private static double nonZero(double a) {
        return 2 * a;
    }

    private static double nonNegative(double a, double b, double c) {
        return Math.pow(b, 2) - (4 * a * c);
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Selection Test 1) 1035 Solution in Java

URI Problem (Selection Test 1) 1035:
Selection Test 1 is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @E-mail : [email protected]
 * @Date : Oct 10, 2016
 * @Time : 12:41:48 AM
 */
public class Uri1035 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, b, c, d;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        if (compareTo(b, c) && compareTo(d, a) && compareTo(sum(c, d), sum(a, b))
                && checkPositive(c) && checkPositive(d) && checkEven(a)) {
            System.out.println("Valores aceitos");
        } else {
            System.out.println("Valores nao aceitos");
        }
    }

    /**
     *
     * @param x given value
     * @param y compare value
     * @return true or false
     */
    private static boolean compareTo(int x, int y) {
        return x > y;
    }

    /**
     *
     * @param x
     * @param y
     * @return sum of x and y
     */
    private static int sum(int x, int y) {
        return x + y;
    }

    /**
     *
     * @param x check positive value
     * @return true or false
     */
    private static boolean checkPositive(int x) {
        return x > 0;
    }

    /**
     *
     * @param x <i>check even</i>
     * @return true or false
     */
    private static boolean checkEven(int x) {
        return x % 2 == 0;
    }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Banknotes and Coins) 1021 Solution in Java

URI Problem (Banknotes and Coins) 1021:
Banknotes and Coins is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.text.DecimalFormat;
import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 9, 2016
 * @Time : 5:42:42 PM
 */
public class Uri1021 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double n = sc.nextDouble();
        if (n >= 0 && n <= 1000000.00) {
            int notes[] = {100, 50, 20, 10, 5, 2};
            double coins[] = {1.00, 0.50, 0.25, 0.10, 0.05, 0.01};
            System.out.println("NOTAS:");
            for (int i = 0; i < notes.length; i++) {
                int t = (int) (n / notes[i]);
                System.out.printf("%d nota(s) de R$ %.2f\n",t ,  (double)notes[i]);             
                n = toDouble(n - notes[i]*t);
            }
            System.out.println("MOEDAS:");
            for (int i = 0; i < coins.length; i++) {
                int t = (int) (n / coins[i]);
                System.out.printf("%d moeda(s) de R$ %.2f\n", (int) (n / coins[i]), coins[i]);
                n = toDouble(n - coins[i]*t);
            }
        }
        
    }
    private static double toDouble(double x){
            DecimalFormat format = new DecimalFormat("#0.00");
            return Double.valueOf(format.format(x));
        }
}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Age in Days) 1020 Solution in Java

URI Problem (Age in Days) 1020:
Age in Days is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 8, 2016
 * @Time   : 10:45:35 PM
 */
public class Uri1020 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int years = n/365;
        int months = n%365;
        int days = months%30;
        months = months/30;
        System.out.println(years+" ano(s)\n"+months+" mes(es)\n"+days+" dia(s)");
    }
}