Skip to content

Instantly share code, notes, and snippets.

@Bahaaib
Last active February 17, 2016 06:16
Show Gist options
  • Select an option

  • Save Bahaaib/1bbbc5e22ae0cee6dd4a to your computer and use it in GitHub Desktop.

Select an option

Save Bahaaib/1bbbc5e22ae0cee6dd4a to your computer and use it in GitHub Desktop.
Number Shape App (New Algorithm)
public class MainActivity extends ActionBarActivity {
class Number {
double x;
String message = "";
public void numTest() {
{
double a = 8 * x + 1;
double b = Math.sqrt(x);
if (Math.sqrt(a)%1 == 0 && x % b == 0) { // To check triangular of number x
message = "Triangular & Square"; // (8x+1) must be a square number
} else if (Math.sqrt(a)%1 == 0 && x % b != 0) {
message = "Triangular";
} else if (Math.sqrt(a)%1 != 0 && x % b == 0) {
message = "Square";
} else {
message = "Neither";
}
}
Toast.makeText(getApplicationContext(),message,Toast.LENGTH_LONG).show();
}
}
public void onClickToCheck(View view) {
String message;
EditText input = (EditText) findViewById(R.id.inpt);
if (input.getText().toString().isEmpty()) {
message = "You haven't Entered any Numbers!";
Toast.makeText(getApplicationContext(),message,Toast.LENGTH_LONG).show();
}
else {
double D_input = Double.parseDouble(input.getText().toString());
Number userNum = new Number();
userNum.x = D_input;
userNum.numTest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment