0% found this document useful (0 votes)
1K views4 pages

Android App for Factorial Calculation

This document describes an Android application that calculates the factorial of a given number. The application has an activity_main.xml layout file with widgets to input a number and display the result. The MainActivity.java code handles the onclick event for the "Find Factorial" button by calculating the factorial of the input number and displaying the answer. The application uses additional files like AndroidManifest.xml and button_background.xml for configuration.

Uploaded by

hdtrs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views4 pages

Android App for Factorial Calculation

This document describes an Android application that calculates the factorial of a given number. The application has an activity_main.xml layout file with widgets to input a number and display the result. The MainActivity.java code handles the onclick event for the "Find Factorial" button by calculating the factorial of the input number and displaying the answer. The application uses additional files like AndroidManifest.xml and button_background.xml for configuration.

Uploaded by

hdtrs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • Practical Explanation and XML Layout
  • Java Code - MainActivity
  • Supporting XML Files
  • Output Screenshot

MCWC LAB(IT-A3) JAYDEEP MATHUKIYA 170160116041

PRACTICAL-8
AIM- Create an application in android to find factorial of a given
number using onClick event.

CODE :-
 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#040404"
android:gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-medium"
android:foregroundGravity="center"
android:padding="22dp"
android:text="Factorial"
android:textColor="#fff"
android:textSize="20dp" />
</LinearLayout>

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:fontFamily="serif-monospace"
android:inputType="number"
android:paddingLeft="12dp"
android:textColor="@color/colorPrimary"
android:textSize="20dp" />

<Button
MCWC LAB(IT-A3) JAYDEEP MATHUKIYA 170160116041
android:id="@+id/find_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="sans-serif-medium"
android:text="Find Factorial"
android:textColor="#050505"
android:textSize="17dp" />

<TextView
android:id="@+id/ans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="sans-serif-medium"
android:text=""
android:textColor="#020202"
android:textSize="20dp" />
</LinearLayout>

 [Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText fact;
Button find_fact;
TextView ans;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
fact = findViewById([Link]);
find_fact = findViewById([Link].find_btn);
ans = findViewById([Link]);
find_fact.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
String data = "";
try {
data = [Link]().toString();
int val = [Link](data);
MCWC LAB(IT-A3) JAYDEEP MATHUKIYA 170160116041
double a = 1;
for (double i = val; i > 0; i--) {
a = a * i;
}
String l = [Link](a);
[Link]("Ans: " + l);
} catch (Exception e) {
[Link]("Incorrect Input");
}
}
});
}
}

 [Link]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

 button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="[Link]
<item>
<shape>
<stroke android:width="1dp" android:color="@color/colorPrimary" />
<solid android:color="@android:color/transparent" />
<corners android:radius="0dp"/>
</shape>
</item>
</selector>
MCWC LAB(IT-A3) JAYDEEP MATHUKIYA 170160116041

 OUTPUT :-

MCWC LAB(IT-A3)
                                   JAYDEEP MATHUKIYA
     
170160116041
PRACTICAL-8 
AIM- Create an applicati
MCWC LAB(IT-A3)
                                   JAYDEEP MATHUKIYA
     
170160116041
        android:id="@+id/find_btn"
MCWC LAB(IT-A3)
                                   JAYDEEP MATHUKIYA
     
170160116041
                    double a = 1;
MCWC LAB(IT-A3)
                                   JAYDEEP MATHUKIYA
     
170160116041
OUTPUT :-

You might also like