Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------
- ActivityMain (XML)
- ----------------------
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:gravity="center"
- tools:context="com.example.user.secondlab.MainActivity"
- android:weightSum="1">
- <Button
- android:id="@+id/b1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="PRIME" />
- <Button
- android:id="@+id/b2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="NEON" />
- </LinearLayout>
- ===============================
- ------------------------------
- Activity Main 2 (XML)
- -----------------------
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:gravity="center"
- tools:context="com.example.user.secondlab.Main2Activity">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Number: "
- android:textSize="25dp"/>
- <EditText
- android:id="@+id/e1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <Button
- android:id="@+id/b3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Check" />
- </LinearLayout>
- =================================
- ------------------------------
- Activity Main 3 (Neon) (XML)
- ---------------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:gravity="center"
- tools:context="com.example.user.secondlab.neon">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Neon Number: "
- android:textSize="25dp"/>
- <EditText
- android:id="@+id/e2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <Button
- android:id="@+id/b4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Check" />
- </LinearLayout>
- ==================================================
- ------------------------------
- MainActivity (Java)
- ----------------------
- package com.example.user.secondlab;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- public class MainActivity extends AppCompatActivity {
- Button bnext;
- Button cnext;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- bnext= (Button) findViewById(R.id.b1);
- cnext= (Button) findViewById(R.id.b2);
- bnext.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent a = new Intent(MainActivity.this, Main2Activity.class);
- startActivity(a);
- finish();
- }
- });
- cnext.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent c = new Intent(MainActivity.this, neon.class);
- startActivity(c);
- finish();
- }
- });
- }
- }
- ==========================
- ------------------------------
- Main2Activity (Java)
- ---------------------
- package com.example.user.secondlab;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class Main2Activity extends AppCompatActivity {
- Button secbtn;
- EditText edit1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main2);
- secbtn = (Button) findViewById(R.id.b3);
- secbtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- edit1 = (EditText) findViewById(R.id.e1);
- String temp = edit1.getText().toString();
- int num=Integer.parseInt(temp);
- int flag=0;
- for(int i=2; i<num; i++)
- {
- if (num% i==0)
- flag=1;
- }
- if (flag==1)
- {
- Toast.makeText(Main2Activity.this, "Not A Prime Number", Toast.LENGTH_SHORT).show();
- }
- else Toast.makeText(Main2Activity.this, "Prime Number", Toast.LENGTH_SHORT).show();
- }
- });
- };
- }
- ===================================
- ------------------------------
- MainActivity (Neon) (Java)
- ------------------------------
- package com.example.user.secondlab;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class neon extends AppCompatActivity {
- Button nbtn;
- EditText edit2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_neon);
- nbtn = (Button) findViewById(R.id.b4);
- nbtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- edit2 = (EditText) findViewById(R.id.e2);
- String temp = edit2.getText().toString();
- int num=Integer.parseInt(temp);
- int result = num * num;
- int sum=0;
- for(int i=result; i>0; i=i/10)
- {
- sum=sum+(i%10);
- }
- if(sum==num)
- {
- Toast.makeText(neon.this, "Neon Number", Toast.LENGTH_SHORT).show();
- }
- else Toast.makeText(neon.this, "Not A Neon Number", Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
- =================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement