Created
March 7, 2022 16:42
-
-
Save shivam-gupta007/e244d469e95b2e7cf8e85a7aa0f70287 to your computer and use it in GitHub Desktop.
Create an app that find Automorphic, Armstrong, Disarium Number
This file contains 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
package com.bca.tca1901074; | |
import android.os.Bundle; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import androidx.appcompat.app.AppCompatActivity; | |
public class ArmstrongNo extends AppCompatActivity { | |
EditText inputNo; | |
Button submitButton; | |
TextView resultText; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_armstrong_no); | |
inputNo = findViewById(R.id.inputNumber); | |
submitButton = findViewById(R.id.submit_button); | |
resultText = findViewById(R.id.text); | |
submitButton.setOnClickListener(view -> { | |
int num = Integer.parseInt(inputNo.getText().toString()); | |
int r, sum = 0, temp; | |
temp = num; | |
while (num > 0) { | |
r = num % 10; | |
sum = sum + (r * r * r); | |
num = num / 10; | |
} | |
if(temp == sum){ | |
resultText.setText("Result: Yes"); | |
}else{ | |
resultText.setText("Result: No"); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment