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



Home Answers Viewqa Java-Beginners Some additions for my previous question

Have Programming Question? Ask it here!
 
 
 


Pam
Some additions for my previous question
2 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners



Advertisement
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
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
Advertisements
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
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
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
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
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
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
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
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
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
NEXT and PREVIOUS Records - JSP-Servlet
NEXT and PREVIOUS Records  Dear Sir, In my Project i have next and previous buttons at bottom of my page which is working fine.But as per our requirement next,previous buttons should be placed at top of the page as well
remove previous view iphone
remove previous view iphone  How to remove previous view in iPhone application on loading a new subview
next and previous record in php
next and previous record in php  How to display next and previous records in PHP
Question
Question   When there is an exception in my program how java runtime system handles
previous view controller
previous view controller  How to get back to the previous view... to go back to the previous view controller. See the example given below...: In an Array the root viewController is at index 0 Previous viewController
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
Mysql Date Previous Month
Mysql Date Previous Month       Mysql Date Previous Month is used to return the current and previous... that help you to describe Previous Month value. To understand this, we have
Output Previous or Next Day of the Month
Output Previous or Next Day of the Month   Please Help! I need... the if...then...else construct and (2) to start using some of the Java API's, by using the String... they want the next day or the previous day. E.g., the user would see: Enter todays
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
PHP Previous Next Page - PHP
PHP Previous Next Page  PHP Previous Next PageIs it possible to create dynamic navigation using PHP and MYSQL? DO I need to create a class to create the next, previous buttons in PHP? I?m digging for a small as well as handy code
question
question  i need a mysql query to take a difference in between current time and previous time.please help me
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  i need a mysql query to take a difference in between current time and previous time from date time colomn in table.please help me
question
question  i need a mysql query to take a date in between current date and previous date from date time colomn in table.please help me View Answers View Answers
question
question  i need a mysql query to take a time in between current time and previous time from date time colomn in table.please help me View Answers
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?  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
Need the some guidence - Spring
Need the some guidence  Hi, MY name is pavan iam having mini projects in MCA these are the details reg projects below 1.project name:identical...; Hi pavan, I show your posted question but not not clear so can
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  please atach java tutorial to my email   Hello Friend, Please visit the following link: Java Tutorial Thanks
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  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
Java Previous Iterator
Java previous Iterator function is present in the listIterator Interface... direction. Java Previous Iterate Example import java.util.ArrayList; import java.util.ListIterator; public class previous { public static void
question
=request.getParameter("address"); %> <html> <h3>Getting values from previous
previous values in servlet - JSP-Servlet
previous values in servlet  Hi... I've an application where there are two links link1 and link2 when i clicked link1 there's a form with relevant drop down lists and text boxes... and similarly to link2...there's another
Sub class of a previous java program
Sub class of a previous java program  Create a Faculty subclass of Employee which has the additional data of rank and expertise. Rank could be one... determined by their run time types and displays all the relevant data. The previous
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
Advertisements
 

 

 

DMCA.com