Advertisement
Tusohian

Prime & Neon Number

Oct 18th, 2019
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.53 KB | None | 0 0
  1. ------------------------------
  2. ActivityMain (XML)
  3. ----------------------
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6.     xmlns:app="http://schemas.android.com/apk/res-auto"
  7.     xmlns:tools="http://schemas.android.com/tools"
  8.     android:layout_width="match_parent"
  9.     android:layout_height="match_parent"
  10.     android:orientation="vertical"
  11.     android:gravity="center"
  12.     tools:context="com.example.user.secondlab.MainActivity"
  13.     android:weightSum="1">
  14.  
  15.     <Button
  16.         android:id="@+id/b1"
  17.         android:layout_width="match_parent"
  18.         android:layout_height="wrap_content"
  19.         android:text="PRIME" />
  20.  
  21.     <Button
  22.         android:id="@+id/b2"
  23.         android:layout_width="match_parent"
  24.         android:layout_height="wrap_content"
  25.         android:text="NEON" />
  26.  
  27. </LinearLayout>
  28.  
  29.  
  30. ===============================
  31.  
  32.  
  33. ------------------------------
  34. Activity Main 2 (XML)
  35. -----------------------
  36.  
  37. <?xml version="1.0" encoding="utf-8"?>
  38. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  39.     xmlns:app="http://schemas.android.com/apk/res-auto"
  40.     xmlns:tools="http://schemas.android.com/tools"
  41.     android:layout_width="match_parent"
  42.     android:layout_height="match_parent"
  43.     android:orientation="vertical"
  44.     android:gravity="center"
  45.     tools:context="com.example.user.secondlab.Main2Activity">
  46.  
  47.  
  48.     <LinearLayout
  49.  
  50.         android:layout_width="match_parent"
  51.         android:layout_height="wrap_content">
  52.  
  53.  
  54.         <TextView
  55.             android:layout_width="wrap_content"
  56.             android:layout_height="wrap_content"
  57.             android:text="Number: "
  58.             android:textSize="25dp"/>
  59.  
  60.         <EditText
  61.             android:id="@+id/e1"
  62.             android:layout_width="match_parent"
  63.             android:layout_height="wrap_content" />
  64.  
  65.     </LinearLayout>
  66.  
  67.     <Button
  68.         android:id="@+id/b3"
  69.         android:layout_width="wrap_content"
  70.         android:layout_height="wrap_content"
  71.         android:text="Check" />
  72.  
  73. </LinearLayout>
  74.  
  75.  
  76. =================================
  77.  
  78.  
  79. ------------------------------
  80. Activity Main 3 (Neon) (XML)
  81. ---------------------------------
  82.  
  83.  
  84. <?xml version="1.0" encoding="utf-8"?>
  85. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  86.     xmlns:app="http://schemas.android.com/apk/res-auto"
  87.     xmlns:tools="http://schemas.android.com/tools"
  88.     android:layout_width="match_parent"
  89.     android:layout_height="match_parent"
  90.     android:orientation="vertical"
  91.     android:gravity="center"
  92.     tools:context="com.example.user.secondlab.neon">
  93.  
  94.  
  95.     <LinearLayout
  96.  
  97.         android:layout_width="match_parent"
  98.         android:layout_height="wrap_content">
  99.  
  100.  
  101.         <TextView
  102.             android:layout_width="wrap_content"
  103.             android:layout_height="wrap_content"
  104.             android:text="Neon Number: "
  105.             android:textSize="25dp"/>
  106.  
  107.         <EditText
  108.             android:id="@+id/e2"
  109.             android:layout_width="match_parent"
  110.             android:layout_height="wrap_content" />
  111.  
  112.     </LinearLayout>
  113.  
  114.  
  115.     <Button
  116.         android:id="@+id/b4"
  117.         android:layout_width="wrap_content"
  118.         android:layout_height="wrap_content"
  119.         android:text="Check" />
  120.  
  121. </LinearLayout>
  122.  
  123.  
  124.  
  125. ==================================================
  126.  
  127.  
  128.  
  129. ------------------------------
  130. MainActivity (Java)
  131. ----------------------
  132. package com.example.user.secondlab;
  133.  
  134. import android.content.Intent;
  135. import android.support.v7.app.AppCompatActivity;
  136. import android.os.Bundle;
  137. import android.view.View;
  138. import android.widget.Button;
  139.  
  140. public class MainActivity extends AppCompatActivity {
  141.  
  142.     Button bnext;
  143.     Button cnext;
  144.  
  145.     @Override
  146.     protected void onCreate(Bundle savedInstanceState) {
  147.         super.onCreate(savedInstanceState);
  148.         setContentView(R.layout.activity_main);
  149.  
  150.         bnext= (Button) findViewById(R.id.b1);
  151.         cnext= (Button) findViewById(R.id.b2);
  152.  
  153.         bnext.setOnClickListener(new View.OnClickListener() {
  154.             @Override
  155.             public void onClick(View v) {
  156.                 Intent a = new Intent(MainActivity.this, Main2Activity.class);
  157.                 startActivity(a);
  158.                 finish();
  159.             }
  160.         });
  161.  
  162.         cnext.setOnClickListener(new View.OnClickListener() {
  163.             @Override
  164.             public void onClick(View v) {
  165.                 Intent c = new Intent(MainActivity.this, neon.class);
  166.                 startActivity(c);
  167.                 finish();
  168.             }
  169.         });
  170.  
  171.     }
  172. }
  173.  
  174.  
  175. ==========================
  176.  
  177.  
  178. ------------------------------
  179. Main2Activity (Java)
  180. ---------------------
  181. package com.example.user.secondlab;
  182.  
  183. import android.content.Intent;
  184. import android.support.v7.app.AppCompatActivity;
  185. import android.os.Bundle;
  186. import android.view.View;
  187. import android.widget.Button;
  188. import android.widget.EditText;
  189. import android.widget.Toast;
  190.  
  191. public class Main2Activity extends AppCompatActivity {
  192.  
  193.     Button secbtn;
  194.     EditText edit1;
  195.  
  196.     @Override
  197.     protected void onCreate(Bundle savedInstanceState) {
  198.         super.onCreate(savedInstanceState);
  199.         setContentView(R.layout.activity_main2);
  200.  
  201.         secbtn = (Button) findViewById(R.id.b3);
  202.  
  203.  
  204.         secbtn.setOnClickListener(new View.OnClickListener() {
  205.             @Override
  206.             public void onClick(View v) {
  207.  
  208.                 edit1 = (EditText) findViewById(R.id.e1);
  209.                 String temp = edit1.getText().toString();
  210.                 int num=Integer.parseInt(temp);
  211.  
  212.                 int flag=0;
  213.                 for(int i=2; i<num; i++)
  214.                 {
  215.                     if (num% i==0)
  216.                         flag=1;
  217.                 }
  218.  
  219.                 if (flag==1)
  220.                 {
  221.                     Toast.makeText(Main2Activity.this, "Not A Prime Number", Toast.LENGTH_SHORT).show();
  222.                 }
  223.                 else Toast.makeText(Main2Activity.this, "Prime Number", Toast.LENGTH_SHORT).show();
  224.  
  225.  
  226.             }
  227.         });
  228.  
  229.     };
  230. }
  231.  
  232. ===================================
  233.  
  234. ------------------------------
  235. MainActivity (Neon) (Java)
  236. ------------------------------
  237.  
  238. package com.example.user.secondlab;
  239.  
  240. import android.support.v7.app.AppCompatActivity;
  241. import android.os.Bundle;
  242. import android.view.View;
  243. import android.widget.Button;
  244. import android.widget.EditText;
  245. import android.widget.Toast;
  246.  
  247. public class neon extends AppCompatActivity {
  248.  
  249.     Button nbtn;
  250.     EditText edit2;
  251.  
  252.     @Override
  253.     protected void onCreate(Bundle savedInstanceState) {
  254.         super.onCreate(savedInstanceState);
  255.         setContentView(R.layout.activity_neon);
  256.  
  257.         nbtn = (Button) findViewById(R.id.b4);
  258.  
  259.         nbtn.setOnClickListener(new View.OnClickListener() {
  260.             @Override
  261.             public void onClick(View v) {
  262.  
  263.                 edit2 = (EditText) findViewById(R.id.e2);
  264.                 String temp = edit2.getText().toString();
  265.                 int num=Integer.parseInt(temp);
  266.  
  267.  
  268.                 int result = num * num;
  269.                 int sum=0;
  270.                 for(int i=result; i>0; i=i/10)
  271.                 {
  272.                     sum=sum+(i%10);
  273.                 }
  274.  
  275.                 if(sum==num)
  276.                 {
  277.                     Toast.makeText(neon.this, "Neon Number", Toast.LENGTH_SHORT).show();
  278.                 }
  279.                 else Toast.makeText(neon.this, "Not A Neon Number", Toast.LENGTH_SHORT).show();
  280.             }
  281.         });
  282.  
  283.     }
  284. }
  285.  
  286. =================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement