Some additions for my previous question

Some additions for my previous question

View Answers

November 21, 2009 at 5:08 PM

Hi Friend,

Try the following codes:
1)
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;
import java.math.*;

class GuiApplication extends JFrame {
JLabel label1, label2;
JTextField text;
JTextArea area;
JScrollPane pane;
JPanel panel, panel1, panel2;
JButton button1, button2;

GuiApplication() {
panel = new JPanel(new GridLayout(3, 2));
panel1 = new JPanel(new GridLayout(3, 2));
panel2 = new JPanel(new GridLayout(3, 2));
label1 = new JLabel("Enter number");
label2 = new JLabel("Result is");
text = new JTextField(15);
area = new JTextArea(2, 2);
pane = new JScrollPane(area);
button1 = new JButton("Check");
button2 = new JButton("Prime Factors");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String value = text.getText();
int i = 0;
Pattern p = Pattern.compile("[A-Z,a-z]");
Matcher m = p.matcher(value);
if (m.find()) {
JOptionPane.showMessageDialog(null,"Please enter only numbers");
} else {
long l = Long.parseLong(value);
BigInteger bigInt = BigInteger.valueOf(l);
if(bigInt.isProbablePrime(10))
area.setText("Number is Prime");
else
area.setText("Number is not Prime");
}
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String value = text.getText();
Pattern p = Pattern.compile("[A-Z,a-z]");
Matcher m = p.matcher(value);
if (m.find()) {
JOptionPane.showMessageDialog(null,
"Please enter only numbers");
} else {
long n = Long.parseLong(value);
long pf=0;
String pfac="";
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {
pf += i;
pfac += Long.toString(i) + " ";
n = n / i;
}
}
area.setText(pfac);
}
}
});
panel1.add(label1);
panel1.add(text);
panel1.add(button1);
panel1.add(button2);
panel2.add(label2);
panel2.add(pane);
panel.add(panel1, BorderLayout.NORTH);
panel.add(panel2, BorderLayout.SOUTH);

add(panel);

}

public static void main(String[] args) {
GuiApplication app = new GuiApplication();
app.setVisible(true);
app.pack();
}
}

November 21, 2009 at 5:09 PM

continue....

2)
import java.util.*;

class Prime{
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!");
}
}

}
class Factors
{
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) {
System.out.print(i + " ");
n = n / i;
}
}
}

}
public class GUI {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("Test");
System.out.println();
System.out.println("1. check prime or not");
System.out.println("2. prime factors");
System.out.println("3. Exit");

boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu) {
case 1:
System.out.print("Enter number: ");
long num=scan.nextLong();
Prime.checkPrime(num);
break;
case 2:
System.out.print("Enter number: ");
long num1=scan.nextLong();
Factors.findFactors(num1);
System.out.println();
break;
case 3:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}

Thanks









Related Tutorials/Questions & Answers:
Some additions for my previous question - Java Beginners
Some additions for my previous question  This is the question I... for the GUI. Could anyone please help?" So my other two questions are: 1... the user with a command line menu. The choices are p, f, q and n. In case
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
Advertisements
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
Addition to my previous post - Java Beginners
Addition to my previous post  Addition to my previous question about the address book program. I need to have separate classes: CmdLineAddressBook.java AddressBook.java Contact.java Address.java Name.java
which query will be run for previous(button) question
which query will be run for previous(button) question   which query will be execute on previous button to view the previous questions . for example... button i got previous question. please provide me the answer
solve my question shortly
solve my question shortly  <html> <head> <script> function checkphoneNumber(number){ if(/[^\d ]/.test(number... the method you have made in script, and there are some more syntactical errors also
my question - EJB
my question  is it possiable to create web application using java beans & EJB's with out implementing Servlets and jsps in that java beans and EJB's
my question is related to my project viz
my question is related to my project viz   Sir, my project is based on MR tracking system developed using struts framework, it has been developed in Net Beans the whole project is working except a jsp page named dayplan.jsp
clarify my question - Java Beginners
clarify my question  Dear Sirs/Expert, Thanks for writing back. Yes. I want a page to use id of parents to do the search for the match. So... the matching tutors to the parent. I was telling you that my degree
Java Question Anyone need some HELP !!
Java Question Anyone need some HELP !!  Create a file that contains your favorite movie quote. Use a text editor such as Notepad and save the file as Quote.txt. Copy the file contents and paste them into a word-processing program
Regarding My 3rd Question in Java - Swing AWT
Regarding My 3rd Question in Java  sir in Netbeans By default JTable Columns will appear Horizontal like Title1 Title2 Title3 Title4 in below these our data will appear so my question that is there any method
ModuleNotFoundError: No module named 'additions'
ModuleNotFoundError: No module named 'additions'  Hi, My Python... 'additions' How to remove the ModuleNotFoundError: No module named 'additions' error? Thanks   Hi, In your python environment you
Clarify my last question's answer - Java Beginners
Clarify my last question's answer  Dear expert, I've tried out... did not specify my question too clearly. Here's my 2 database... and parents contain other fields like name, address, email, contact numbers etc. My
PLZ Need some help on the 2nd part of this question...Someone please help !!!!
PLZ Need some help on the 2nd part of this question...Someone please help !!!!  write an application that displays a menue of three items in a restaurant as follows: 1.Cheeseburger 4.99 2.Pepsi 2.00 3.Chips 0.75 prompt the user
ModuleNotFoundError: No module named 'allure-additions'
ModuleNotFoundError: No module named 'allure-additions'  Hi, My... named 'allure-additions' How to remove the ModuleNotFoundError: No module named 'allure-additions' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'git-additions'
ModuleNotFoundError: No module named 'git-additions'  Hi, My... 'git-additions' How to remove the ModuleNotFoundError: No module named 'git-additions' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'mikado.oss.doctest_additions'
ModuleNotFoundError: No module named 'mikado.oss.doctest_additions'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'mikado.oss.doctest_additions' How to remove
ModuleNotFoundError: No module named 'pip-additions'
ModuleNotFoundError: No module named 'pip-additions'  Hi, My... 'pip-additions' How to remove the ModuleNotFoundError: No module named 'pip-additions' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'unittest-additions'
ModuleNotFoundError: No module named 'unittest-additions'  Hi, My... named 'unittest-additions' How to remove the ModuleNotFoundError: No module named 'unittest-additions' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'allure-additions'
ModuleNotFoundError: No module named 'allure-additions'  Hi, My... named 'allure-additions' How to remove the ModuleNotFoundError: No module named 'allure-additions' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'git-additions'
ModuleNotFoundError: No module named 'git-additions'  Hi, My... 'git-additions' How to remove the ModuleNotFoundError: No module named 'git-additions' error? Thanks   Hi, In your python
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
hi,i'am new to Jsp.Can some one please let me know an answer for this question?
hi,i'am new to Jsp.Can some one please let me know an answer for this question?  how do we upload an xml file and validate them against WIPO DTD
ModuleNotFoundError: No module named 'django-admin-additions'
ModuleNotFoundError: No module named 'django-admin-additions'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'django-admin-additions' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'django-admin-additions'
ModuleNotFoundError: No module named 'django-admin-additions'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'django-admin-additions' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'django-auth-additions'
ModuleNotFoundError: No module named 'django-auth-additions'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'django-auth-additions' How to remove the ModuleNotFoundError
in my project, i have to add scrollbars to a panel,. i need some example on it,how to doit.
in my project, i have to add scrollbars to a panel,. i need some example on it,how to doit.  in my project, i have to add scrollbars to a panel,. i need some example on it,how to doit. Thanks In Advance   Please
Further advice needed on my last question - JSP-Servlet
Further advice needed on my last question  Dear Experts, I refer to your last solution regarding my matching codes. After I tried out your... errors Here are my codes which I modified but basically followed your logic
Question
Question   When there is an exception in my program how java runtime system handles
in my project, i have to add only vertical scrollbar to a panel,but not horizontal scrollbar. i need some example on it,how to doit.
in my project, i have to add only vertical scrollbar to a panel,but not horizontal scrollbar. i need some example on it,how to doit.  in my project.... i need some example on it,how to doit. Thanks in advance
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  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   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
How to install virtualbox guest additions in Ubuntu 16.04?
How to install virtualbox guest additions in Ubuntu 16.04?  Hi, How to install virtualbox guest additions in Ubuntu 16.04? The problem is I am not able to copy the text through clipboard, I think virtualbox guest additions
question
question  Sir , i have a starting trouble to start my search engine project , please help me to start my project , please send me some relevant java codes
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  Sir, Please help me to develop a simple search engine model in java , send me some codes
question
question  i need to select some details form database and that will displays on the same jsp page which is already contains some other details ,mustn't go to next page while i am clicking a link. have any option in jsp or java
question
question  i need to select data from database using mysql+java script+html   Please specify some more details
question
question  following is my code to sent mail but i couldn't work with eclipse ,that have some errors .need i any set up in eclipse or tell to what can i do to work code properly. <%@ page import="java.io." import="java.lang.
question
question  suppose i had downloaded the zip file,extracted it in local directory so how automatically will it integrate with eclipse? i mean do i need to set some path or something
QUESTION
QUESTION  please atach java tutorial to my email   Hello Friend, Please visit the following link: Java Tutorial Thanks
question
question  i am using this code in my project response.sendRedirect("LoginForm1.jsp?msg=Username or Password is incorrect!"); but i wan't to hide this message from url.please help me
question
question  Sir, how to display web snippets for a perticular query for eg:web snippets for apple how to implement this concept in my java project please help me
question
question  i need to mark employees as half day absent who came after 10'o clock in my web project,so i need to know who are all late entry.if you have any idea using jsp and mysql please help me
question
to develop my java project
question
question  Sir, i am developing a video streaming PC server to j2me client system that the j2me player can playing video from PC server .if have any code for video streaming then send to my email address as soon as possible
question
/) is not available.** how tdo i solve this.please help me to run my project please give
question
question  i need a mysql query to take a difference in between current time and previous time.please help me

Ads