Last active
February 17, 2016 06:16
-
-
Save Bahaaib/1bbbc5e22ae0cee6dd4a to your computer and use it in GitHub Desktop.
Number Shape App (New Algorithm)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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