Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

10/11/23, 2:27 PM Automorphic and Prime Number Menu Driven Java Program | KnowledgeBoat

Home / Java Numbe… / Automorphic a…

Java Number Programs (ICSE Classes 9 / 10)

Write a menu driven program to accept a number from the user and check
whether it is a Prime number or an Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and
itself)
Example: 3,5,7,11
(b) Automorphic number: (Automorphic number is the number which is
contained in the last digit(s) of its square.)
Example: 25 is an Automorphic number as its square is 625 and 25 is present as
the last two digits.
Java Java Iterative Stmts ICSE

121 Likes

Rs 6,850 Rs 3,150 Rs 2,790 Rs 10,560

ANSWER

import java.util.Scanner;

public class KboatPrimeAutomorphic


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Prime number");
System.out.println("2. Automorphic number");
System.out.print("Enter your choice: ");
int choice = in.nextInt();
System.out.print("Enter number: ");
int num = in.nextInt();

https://www.knowledgeboat.com/question/write-a-menu-driven-program-to-accept-a-number-from-the-user--32577997686630360?studylist=num… 1/7
10/11/23, 2:27 PM Automorphic and Prime Number Menu Driven Java Program | KnowledgeBoat

switch (choice) {
case 1:
int c = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
c++;
}
}
if (c == 2)
System.out.println(num + " is Prime");
else
System.out.println(num + " is not Prime");
break;

case 2:
int numCopy = num;
int sq = num * num;
int d = 0;

/*
* Count the number of
* digits in num
*/
while(num > 0) {
d++;
num /= 10;
}

/*
* Extract the last d digits
* from square of num
*/
int ld = (int)(sq % Math.pow(10, d));

if (ld == numCopy)
Prev System.out.println(numCopy + " is automorphic");
All Questions Next
else
System.out.println(numCopy + " is not automorphic");
break;

default:
System.out.println("Incorrect Choice");
break;
}
}
}

OUTPUT
BlueJ output of Write a menu driven program to accept a number from the user and check whether it is a Prime
number or an Automorphic number. (a) Prime number: (A number is said to be prime, if it is only divisible by 1 and itself)
Example: 3,5,7,11 (b) Automorphic number: (Automorphic number is the number which is contained in the last digit(s) of
its square.) Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last two digits.

https://www.knowledgeboat.com/question/write-a-menu-driven-program-to-accept-a-number-from-the-user--32577997686630360?studylist=num… 2/7
10/11/23, 2:27 PM Automorphic and Prime Number Menu Driven Java Program | KnowledgeBoat
BlueJ output of Write a menu driven program to accept a number from the user and check whether it is a Prime
number or an Automorphic number. (a) Prime number: (A number is said to be prime, if it is only divisible by 1 and itself)
Example: 3,5,7,11 (b) Automorphic number: (Automorphic number is the number which is contained in the last digit(s) of
its square.) Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last two digits.

Answered By
40 Likes

ICSE/ISC TEXTBOOK SOLUTIONS

Class - 6 Concise Biology Selina Solutions

Class - 6 Veena Bhargava Geography Solutions

Class - 6 Effective History & Civics Solutions


https://www.knowledgeboat.com/question/write-a-menu-driven-program-to-accept-a-number-from-the-user--32577997686630360?studylist=num… 3/7
10/11/23, 2:27 PM Automorphic and Prime Number Menu Driven Java Program | KnowledgeBoat

Class - 6 APC Understanding Computers Solutions

Class - 7 Concise Physics Selina Solutions

Class - 7 Concise Chemistry Selina Solutions

Class - 7 Dalal Simplified Middle School Chemistry Solutions

Class - 7 Concise Biology Selina Solutions

Class - 7 Living Science Biology Ratna Sagar Solutions

Class - 7 Around the World Geography Solutions

Class - 7 Veena Bhargava Geography Solutions

Class - 7 Effective History & Civics Solutions

Class - 7 APC Understanding Computers Solutions

Class - 8 Concise Physics Selina Solutions

Class - 8 Concise Chemistry Selina Solutions

Class - 8 Dalal Simplified Middle School Chemistry Solutions

Class - 8 Concise Biology Selina Solutions

Class - 8 Living Science Biology Ratna Sagar Solutions

Class - 8 Around the World Geography Solutions

Class - 8 Veena Bhargava Geography Solutions

Class - 8 Effective History & Civics Solutions

Class - 8 APC Understanding Computers Solutions

https://www.knowledgeboat.com/question/write-a-menu-driven-program-to-accept-a-number-from-the-user--32577997686630360?studylist=num… 4/7
10/11/23, 2:27 PM Automorphic and Prime Number Menu Driven Java Program | KnowledgeBoat

Class - 8 Kips Logix Computers Solutions

Class - 9 Concise Physics Selina Solutions

Class - 9 Concise Chemistry Selina Solutions

Class - 9 Dalal Simplified ICSE Chemistry Solutions

Class - 9 Concise Biology Selina Solutions

Class - 9 Total Geography Morning Star Solutions

Class - 9 Veena Bhargava Geography Solutions

Class - 9 Total History & Civics Solutions

Class - 9 APC Understanding Computers Solutions

Class - 9 Kips Logix Computers Solutions

Class - 10 ML Aggarwal Mathematics Solutions

Class - 10 Concise Physics Selina Solutions

Class - 10 Concise Chemistry Selina Solutions

Class - 10 Dalal Simplified ICSE Chemistry Solutions

Class - 10 Concise Biology Selina Solutions

Class - 10 Total Geography Morning Star Solutions

Class - 10 Veena Bhargava Geography Solutions

Class - 10 Total History & Civics Solutions

Class - 10 APC Modern History & Civics Solutions

https://www.knowledgeboat.com/question/write-a-menu-driven-program-to-accept-a-number-from-the-user--32577997686630360?studylist=num… 5/7
10/11/23, 2:27 PM Automorphic and Prime Number Menu Driven Java Program | KnowledgeBoat

Class - 10 APC Understanding Computers Solutions

Class - 10 Sumita Arora ICSE Computers Solutions

Class - 10 Kips Logix Computers Solutions

Class - 11 APC Understanding Computers Solutions

Class - 12 APC Understanding Computers Solutions


ICSE/ISC SOLVED QUESTION PAPERS

ICSE Class 10 Computers Solved 10 Yrs Question Papers

Sample Papers ICSE Class 10 Computer Applications

ICSE Class 10 Physics Solved 10 Yrs Question Papers

ICSE Class 10 Chemistry Solved 10 Yrs Question Papers

ICSE Class 10 Biology Solved 10 Yrs Question Papers

Class - 12 ISC Computer Science Solved Practical Papers

STUDYLIST

Java Pattern Programs

Java Series Programs

Java Number Programs (ICSE Classes 9 / 10)

Java Number Programs (ISC Classes 11 / 12)

Output Questions for Class 10 ICSE Computer Applications

Algorithms & Flowcharts for ICSE Computers

https://www.knowledgeboat.com/question/write-a-menu-driven-program-to-accept-a-number-from-the-user--32577997686630360?studylist=num… 6/7
10/11/23, 2:27 PM Automorphic and Prime Number Menu Driven Java Program | KnowledgeBoat

ICSE Class 8 Computers Differentiate Between the Following


CBSE TEXTBOOK SOLUTIONS

Class - 9 NCERT Geography Contemporary India 1 Solutions

Class - 9 Sumita Arora Computer Code 165 Solutions

Class - 10 NCERT Science Solutions

Class - 10 NCERT Geography Contemporary India 2 Solutions

Class - 10 Sumita Arora Computer Code 165 Solutions

Class - 10 Kips Cyber Beans Computer Code 165 Solutions

Class - 11 CBSE Sumita Arora Python Solutions

Class - 12 CBSE Sumita Arora Python Solutions

COMPANY

About Us

Contact Us

Privacy Policy

Terms of Service

Copyright © KnowledgeBoat 2023

https://www.knowledgeboat.com/question/write-a-menu-driven-program-to-accept-a-number-from-the-user--32577997686630360?studylist=num… 7/7

You might also like