0% found this document useful (0 votes)
24 views3 pages

Exp 18 3

The document describes creating two screens in an Android app. The first screen takes a number input and displays a button. When the button is clicked, it opens the second screen displaying the factorial of the input number using an explicit intent.

Uploaded by

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

Exp 18 3

The document describes creating two screens in an Android app. The first screen takes a number input and displays a button. When the button is clicked, it opens the second screen displaying the factorial of the input number using an explicit intent.

Uploaded by

Shivraj Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Write a program to create two screens.

First screen will take one number input


from user. After click on Factorial button, second screen will open and it should
display factorial of the same number. Also specify which type of intent you will
use in this case.
activity_main.xml MainActivity.java
<?xml version="1.0" encoding="UTF-8" ?> package com.example.exp_18_3;
<LinearLayout
xmlns:android="http://schemas.android.com/apk/re import
s/android" androidx.appcompat.app.AppCompatActivity;
android:layout_width="match_parent"
android:layout_height="match_parent" import android.content.Intent;
android:layout_margin="30dp" import android.os.Bundle;
android:orientation="vertical"> import android.view.View;
import android.widget.Button;
<EditText import android.widget.EditText;
android:id="@+id/editText"
android:layout_width="wrap_content" public class MainActivity extends
android:layout_height="wrap_content" AppCompatActivity {
android:layout_gravity="center" EditText editText;
android:hint="Enter No." Button button;
android:textSize="20dp"
android:ems="8"/> @Override
protected void onCreate(Bundle
<Button savedInstanceState) {
android:id="@+id/btn" super.onCreate(savedInstanceState);
android:layout_width="wrap_content" setContentView(R.layout.activity_main);
android:layout_height="wrap_content" editText = findViewById(R.id.editText);
android:layout_gravity="center" button = findViewById(R.id.btn);
android:text="Factorial"
android:textSize="20dp" /> button.setOnClickListener(new
</LinearLayout> View.OnClickListener() {
@Override
public void onClick(View v) {
Intent in = new
Intent(MainActivity.this, fcat.class);
in.putExtra("factorial",
Integer.parseInt(editText.getText().toString()));
startActivity(in);
}
});
}
}
activity_fact.xml Fact.java
<?xml version="1.0" encoding="UTF-8" ?> package com.example.exp_18_3;
<LinearLayout import android.os.Bundle;
xmlns:android="http://schemas.android.com/apk/r import
es/android" androidx.appcompat.app.AppCompatActivity;
android:layout_width="match_parent" import android.widget.EditText;
android:layout_height="match_parent" import
android:layout_margin="30dp" com.example.exp_18_3.databinding.ActivityFc
android:orientation="vertical"> atBinding;
public class fcat extends AppCompatActivity {
<LinearLayout EditText et;
android:layout_width="wrap_content" int fact = 1;
android:layout_height="wrap_content" private ActivityFcatBinding binding;
android:layout_gravity="center">
@Override
<TextView protected void onCreate(Bundle
android:layout_width="wrap_content" savedInstanceState) {
android:layout_height="wrap_content" super.onCreate(savedInstanceState);
android:text="Factoral:"
android:layout_marginRight="5dp" binding =
android:textSize="20dp"/> ActivityFcatBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
<EditText
android:id="@+id/et" et = findViewById(R.id.et);
android:layout_width="wrap_content" int val = getIntent().getIntExtra("factorial",
android:layout_height="wrap_content" 0);
android:editable="false" if (val == 1) {
android:ems="8" fact = 1;
android:textSize="20dp" } else {
/> for (int i = val; i > 0; i--) {
</LinearLayout> fact = fact * i;
</LinearLayout> }
}
et.setText(String.valueOf(fact));
}
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy