Skip to content

Instantly share code, notes, and snippets.

@AndresRodz
AndresRodz / SimpleDishes.java
Created December 2, 2013 04:37
It has a weight of simple dishes, and weights of 1kg, 2kg, 4kg, 8kg, 16Kg, ..., up to 2^14kg. And he wants to weigh objects whose total weight is less than 2^15 kg. You are required to develop a software that, given the weight of the object find which dishes you need to use to do their weighing. The weights are properly numbered with a value 0 <…
import java.util.Scanner;
import java.lang.Math;
public class SimpleDishes{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
int t = input.nextInt();
@AndresRodz
AndresRodz / ArmyStrength.java
Created December 2, 2013 04:36
The next MechaGodzilla invasion is on its way to Earth. And once again, Earth will be the battleground for an epic war. MechaGodzilla's army consists of many nasty alien monsters, such as Space Godzilla, King Gidorah, and MechaGodzilla herself. To stop them and defend Earth, Godzilla and her friends are preparing for the battle. Each army consis…
import static java.lang.Integer.*;
import static java.lang.Math.*;
import java.util.*;
import java.io.*;
public class ArmyStrength {
public static void main(String[] args) throws Throwable{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
@AndresRodz
AndresRodz / GeneralElection.java
Created December 2, 2013 04:33
General Election is over, now it is time to count the votes! There are n (2 <= n <= 5) candidates and m (1 <= m <= 100) vote regions. Given the number of votes for each candidate from each region, determine which candidate is the winner (one with the most votes). Input specification The first line of input contains an integer T (1 <= T <= 100), …
import java.io.*;
import java.util.Scanner;
public class GeneralElection {
public static void main(String [] args) {
Scanner scan = new Scanner(System.in);
int elections = scan.nextInt();
@AndresRodz
AndresRodz / AsteriskTriangle.java
Created November 14, 2013 00:21
Exercise 10: Write a program (save it as AsteriskTriangle) that prompts the user for an integer number and then it would display a line of asterisks for each number between 1 and the given number. The number of asterisks on each line will be according to each number.
import java.util.Scanner;
public class AsteriskTriangle {
public static void main (String [] args) {
// Variables
Scanner input = new Scanner(System.in);
int number;
@AndresRodz
AndresRodz / PerfectNumber.java
Created November 14, 2013 00:20
Exercise 9: Write a program that asks the user how many numbers he wants to analyze. The program then asks the user for an integer and the program will display the legend: “this is a perfect number” or “this NOT a perfect number” accordingly. The program will ask for numbers as many times as the user established when the program started. NOTE: A…
import java.util.Scanner;
public class PerfectNumber {
public static void main (String [] args) {
// Variables
Scanner input = new Scanner(System.in);
int analyze, lowLimit, highLimit;
@AndresRodz
AndresRodz / ClassifyNumbers.java
Created November 14, 2013 00:18
Exercise 8: Write a program that asks the user how many numbers he wants to analyze and the low and high integer in a range of integers. The program then will start asking the user for integers and the program will display the legend: “This number is out of range” or “This number is within range” accordingly. The program will ask for numbers as …
import java.util.Scanner;
public class ClassifyNumbers {
public static void main (String [] args) {
// Variables
Scanner input = new Scanner(System.in);
int limit, low, high, inside, sum, count;
@AndresRodz
AndresRodz / CreditCard.java
Created November 14, 2013 00:17
Exercise 7: Say that you owe the credit card company $1000.00. The company charges you 1.5% per month on the unpaid balance. You have decided to stop using the card and to pay off the debt by making a monthly payment of N dollars a month. Write a program (save it as CreditCard) that asks for the monthly payment, then writes out the balance and t…
import java.util.Scanner;
public class CreditCard {
public static void main (String [] args) {
// Variables
Scanner input = new Scanner(System.in);
double payment, debt;
int month;
@AndresRodz
AndresRodz / CountingLetters.java
Created November 14, 2013 00:15
Exercise 6: Write a program (save it as CountingLetters) that asks the user to enter two words. The program then prints out both words on the same line. The words will be separated by enough dots so that the total length of the line is 30 characters. To do this you will need to use the length( ) method that counts the number of characters in a s…
import java.util.Scanner;
public class CountingLetters {
public static void main (String [] args) {
// Variables
Scanner input = new Scanner(System.in);
String word1, word2, end;
int length, dotlength;
@AndresRodz
AndresRodz / MilesPerGallon.java
Created November 14, 2013 00:13
Exercise 5: Write a program (save it as MilesPerGallon) that calculates miles per gallon for a list of cars. The data for each car consists of initial odometer reading, final odometer reading, and number of gallons of gas. The user signals that there are no more cars by entering a negative initial odometer reading.
import java.util.Scanner;
public class MilesPerGallon {
public static void main (String [] args) {
// Variables
Scanner input = new Scanner(System.in);
double milespergallon;
@AndresRodz
AndresRodz / MoreTirePressure.java
Created November 14, 2013 00:11
Exercise 4: Make a copy of your TirePressure java file. Save it as MoreTirePressure and rewrite it according to the following situation: It is not enough that the pressures are the same in the tires, but the pressures must also be within range. Your program should check that each tire has a pressure between 35 and 45. If a tire is out of range, …
import java.util.Scanner;
public class MoreTirePressure {
public static void main (String [] args) {
// Variables
Scanner input = new Scanner(System.in);
// Ejecucion