Skip to content

Instantly share code, notes, and snippets.

@Aleyasen
Last active January 21, 2016 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aleyasen/778ddf447820d28fb961 to your computer and use it in GitHub Desktop.
Save Aleyasen/778ddf447820d28fb961 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salman;
/**
*
* @author Amirhossein Aleyasen <aleyase2@illinois.edu>
*/
public class Salman {
public static void main(String[] args) {
// int[] a = {4, 3, 6, 7, 2, 12, 11};
// System.out.println(multThreeSum(a));
String[] arr = {"Salam", "Bye", "Hello"};
System.out.println(findSearch(arr, "Salam"));
System.out.println(findSearch(arr, "Salam2"));
}
public static boolean findSearch(String[] array, String search) {
for (String str : array) {
if (str.equals(search)) {
return true;
}
}
return false;
}
public static int multThreeSum(int[] array) {
int sum = 0;
for (int val : array) {
if (val % 3 == 0) {
sum = sum + val;
}
}
return sum;
}
}
class Bear {
String name;
int height;
double speed;
public Bear(String name, int height, double speed) {
this.name = name;
this.height = height;
this.speed = speed;
}
@Override
public String toString() {
return name + " " + height + " " + speed;
}
public double getSpeed() {
return speed;
}
public void climbTree() {
// do climb
}
}
class Bears {
private Bear[] myBears;
int count;
public Bears() {
myBears = new Bear[50];
// count = 0;
}
public void myBears(String[] names, int[] height, double[] speed) {
for (int i = 0; i < names.length; i++) {
Bear b = new Bear(names[i], height[i], speed[i]);
// myBears[count] = b;
// count++;
int index = 0;
for (int j = 0; j < 50; j++) {
if (myBears[j] == null) {
index = j;
break;
}
}
myBears[index] = b;
}
}
public void allClimbTree() {
for (int i = 0; i < 50; i++) {
if (myBears[i] != null) {
myBears[i].climbTree();
}
}
}
public void sortBears() {
for (int i = 0; i < myBears.length; i++) {
int smallestIndex = i;
for (int j = i + 1; j < myBears.length - 1; j++) {
if (myBears[j].getSpeed() > myBears[smallestIndex].getSpeed()) {
smallestIndex = j;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment