Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Another Question

Have Programming Question? Ask it here!
 
 
 


Pam
Another Question
1 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners



Advertisement
View Answers

November 23, 2009 at 12:11 PM


Hi Friend,

Save the following code in the java file with name 'PrimesCMDLine.java'.

import java.util.*;

class PrimesCMDLine {
public static void checkPrime(long num){
long i=0;
for ( i = 2; i < num; i++) {
long n = num % i;
if (n == 0) {
System.out.println("Entered number is not Prime!");
break;
}
}
if (i == num) {
System.out.println("Number is Prime!");
}
}



public static void findFactors(long n){
System.out.print("The prime factorization of " + n + " is: ");
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {

n = n / i;
System.out.print(i + " ");
}
}
if (n > 1) System.out.println(n);
else System.out.println();
}


public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
String menu = "";
System.out.println("Test");
System.out.println();
System.out.println("p. check prime or not");
System.out.println("f. prime factors");
System.out.println("e. Exit");

boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.next();
System.out.println();
char ch=menu.charAt(0);
switch(ch) {
case 'p':
System.out.print("Enter number: ");
long num=scan.nextLong();
PrimesCMDLine .checkPrime(num);
break;
case 'f':
System.out.print("Enter number: ");
long num1=scan.nextLong();
PrimesCMDLine .findFactors(num1);
System.out.println();
break;
case 'e':
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}

Thanks


Related Tutorials/Questions & Answers:
Another Question - Java Beginners
Another Question  This is the question I posted yesterday: "I'm... with a command line menu. The choices are p, f, q and n. In case of choice n, ask the user... great! The only thing is how do I make the command line to accept letters p, f, q
sir i,have a another assignment for these question plz help me sir - JavaMail
sir i,have a another assignment for these question plz help me sir  ... serialization. Write another program to read that file, convert to Rupee.... Design another thread that generates fibonacci numbers and writes them
Advertisements
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
question
question  i need a simple javascript or jsp code to send message from one mail to another mail
question
question  i need a simple javascript or jsp code to send message from one mail to another mail
question
question  i need a jsp/html program which includes drop down menu for leave types and a button for apply leave.and need another jsp to validate types of leave and then insert in to data base using mysql
question
question  Sir, How to stream video on one computer which is playing on another PC in LAN using java + socket / RMI . if you have any idea about that please help me and give the source code
question
question  good afternoon sir, i need a jsp/html program which includes drop down menu for leave types and a button for apply leave.and need another jsp to insert types of leave which is selected by the user ,in to data base
question
on Leave Another grid to show the employees who are on leave Using JPannel,java
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog
question
question  hi good morning. how to retrive the data from one form of jsp to another form.please help me   Hi Friend, Try the following code: 1)form1.jsp: <html> <form method="post" action="form2.jsp"> <
question
question  Sir, how to write the following code in jsp , avoid swing components , please give me the following code in another method , iwant to avoid swing . /* * To change this template, choose Tools | Templates
Question in Eclipse
Question in Eclipse   ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square... variable side. 5.Add another constructor that takes one argument, the side
Question in Eclipse ??
Question in Eclipse ??  ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square... of instance variable side. 5.Add another constructor that takes one argument, the side
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
ArrayList as an argument to another class
ArrayList as an argument to another class  how do you pass arraylists as arguments to another class, and how does the method/class accept this arraylist for use
jsf: generate another panelGrid
jsf: generate another panelGrid  hello the following is my code print("code sample"); <%@ taglib uri="http://java.sun.com/jsf/html" prefix... generate another panelgrid with the same number of columns and rows (Each time I
Question in eclipes ??!!
Question in eclipes ??!!  Hooole EveryOne I have Question in eclipes !!? Question is : The objectives of this lab are 1.Using the â?? this... ) Design another class to test the Complex class. Ensure that all your methods
I/O to another applications
I/O to another applications  **What if there exists an application that needs a certain input and will give an output. Using Java, how can we invoke that application with an input and read the resulted output?**   Hi
XML Interviews Question page19
XML Interviews Question page19   ... namespaces? I don't know the answer to this question, but the likely reason... document to another document. An early draft of the XML namespaces recommendation
include' a HTML document in another document.
include' a HTML document in another document.  I'm trying to `include' a HTML document in another document...Is there a way to do
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
Can an Interface implement another Interface?
Can an Interface implement another Interface?   Hi, Can an Interface implement another Interface? Thanks
Can an Interface extend another Interface?
Can an Interface extend another Interface?   Hi, Can an Interface extend another Interface? thanks
Question on pooling
Question on pooling  which server supports pooling?Application server or web server
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
Question on javascript
Question on javascript  There will be two combo box in HTML form.If selecting in one combo box(ex:child id=1),the corresponding one to one matched value(ex:Child name=ashish) get selected automatically in another combo box.How
This question in Jmeter
This question in Jmeter  hi..i want to send request(xml) 100 times but each time in request xml one element needs to change, otherwise request will be failed since its duplicate
Question on javascript
Question on javascript  This is not exactly what i wanted....If i enter in 2nd combobox as name of child then it should show child id in 1st combobox automatically and vice versa
C# question
Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs and savingsTest.cs to Demonstrate Abstract Classes in C#  1st question : Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10
parser xml one page to another
parser xml one page to another  parser xml one page to another
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz  
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz View
Use varibles from another class
Use varibles from another class  **I have two classes. class 1:** public class askfigures extends JFrame { method from class1: public void... in another class. another class: public class Askvalues extends JFrame
Core Java Interview Question, Interview Question
Core Java Interview Question Page 21       Question: How are the elements of a GridLayout... and are laid out using the squares of a grid. Question: What an I/O filter? Answer: An I
basic question
basic question  how we create a new table with the same structure and data of another table
Question in Java ??
Question in Java ??   Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number squrfoot
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
Core Java Interview Question, Interview Question
in that package but not from classes in another package Question: How can you access... Core Java Interview Question Page 27       Modifiers Question: What are access modifiers
 

 

 

DMCA.com