Hack #1
import java.util.*;
public class Main{
public static ArrayList<Integer> numbers = new ArrayList<Integer>();
public static void AppendArray(int number){
numbers.add(number);
}
public static int callNum(int num){
return numbers.get(num);
}
public static void main(String[] args){
numbers.add(5);
Scanner input = new Scanner(System.in);
int number = input.nextInt();
AppendArray(number);
int index = input.nextInt();
System.out.println(callNum(index));
}
}
Main.main(null);
5
Hack #2
import java.util.*;
public class GuessingGame {
private static Random random = new Random();
private int base;
private int exponent;
public GuessingGame() {
base = random.nextInt(9);
exponent = random.nextInt(4);
}
public void play() {
Scanner input = new Scanner(System.in);
int guessBase;
int guessExponent;
System.out.println("Hello Stranger! Welcome to my Guessing Game!");
System.out.println("I've selected a random number taken to a random exponent.");
System.out.println("Guess the number and exponent! GOOD LUCK!");
do {
System.out.println("Guess the base; then the exponent");
guessBase = input.nextInt();
guessExponent = input.nextInt();
if (guessBase == base && guessExponent == exponent) {
System.out.println("You are correct.");
} else {
giveHint(guessBase, guessExponent);
}
} while (guessBase != base || guessExponent != exponent);
input.close();
}
private void giveHint(int guessBase, int guessExponent) {
if (guessBase < base) {
System.out.println("Rip! Try a larger base.");
} else if (guessBase > base) {
System.out.println("Rip! Try a smaller base.");
} else {
System.out.println("Base is correct!");
if (guessExponent < exponent) {
System.out.println("Rip! Try a larger exponent.");
} else if (guessExponent > exponent) {
System.out.println("Rip! Try a smaller exponent.");
} else {
System.out.println("Exponent is correct!");
}
}
}
public static void main(String[] args) {
GuessingGame game = new GuessingGame();
game.play();
}
}
GuessingGame.main(null);
Hack #3
class Person{
public String firstname;
public String lastname;
public int age;
public double salary;
public boolean tall;
public Person(String firstName, String lastName, int Age, double Salary, boolean Tall){
this.firstname = firstName;
this.lastname = lastName;
this.age = Age;
this.salary = Salary;
this.tall = Tall;
}
public String Name(){
return this.firstname + " "+this.lastname;
}
public int age(){
return this.age;
}
public double salary(){
return this.salary;
}
public boolean height(){
if (this.tall){
return true;
}
else{
return false;
}
}
}
public class Main{
public static void main(String[] args){
Person tom = new Person("Tom","Anderson",20,10000,false);
System.out.println("Name: " + tom.Name());
System.out.println("Age: " + tom.age());
System.out.println("I have $"+ tom.salary);
System.out.println("Me tall: " + tom.tall);
}
}
Main.main(null);
Name: Tom Anderson
Age: 20
I have $10000.0
Me tall: false
Hack #4
import java.lang.String;
public class NameFinder{
public static String firstName(String name){
String firstName = "";
//First name
int spaceIndex = name.indexOf(" ");
for (int i = 0; i<spaceIndex;i++){
firstName += name.charAt(i);
}
return firstName;
}
public static String lastName(String name){
String lastName = "";
//Last name
int spaceIndex = name.indexOf(" ");
for (int i = spaceIndex+1; i<name.length(); i++){
lastName += name.charAt(i);
}
return lastName;
}
public static void main(String[] args){
String name = "Ratchet Hammer";
System.out.println(firstName(name));
System.out.println(lastName(name));
}
}
NameFinder.main(null);
Ratchet
Hammer