ishan
simple code
2 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners

View Answers

January 12, 2009 at 11:21 PM


Hi friend,

Code to help in solving the problem :

import java.io.*;

class PrimeNumber {
public static void main(String[] args) throws Exception{
int i;
BufferedReader bf = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter number:");
int num = Integer.parseInt(bf.readLine());
System.out.println("Prime number: ");
for (i=1; i < num; i++ ){
int j;
for (j=2; j<i; j++){
int n = i%j;
if (n==0){
break;
}
}
if(i == j){
System.out.print(" "+i);
}
}
}
}

Thanks

January 13, 2009 at 12:19 AM


Hi friend,


import java.io.*;

class PrimeDemo {
public static void main(String[] args) throws Exception{
int i;
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number:");
int num = Integer.parseInt(buff.readLine());
System.out.println("Prime number: ");
for (i=1; i < num; i++ ){
int j;
for (j=2; j<i; j++){
int n = i%j;
if (n==0){
break;
}
}
if(i == j){
System.out.print(" "+i);
}
}
}
}

--------------------------------


Visit for more information:

http://www.roseindia.net/java/

Thanks.









Related Pages:
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving... is acceptable). Thanks.   Please visit the following link: Simple EJB
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving... is acceptable). Thanks.   Please visit the following link: Simple EJB
simple code - Java Beginners
simple code  to input a number and check wether it is prime or not and print its position in prime nuber series.  Hi friend, Code to help in solving the problem : import java.io.*; class PrimeNumber { public
Simple ATM Java Code...
Simple ATM Java Code...  You are required to write a Graphical User Interface that simulates an ATM by building on the program you wrote.... It's a college assignment and needs to be written with the least amount of code
simple code for XML database in JS
simple code for XML database in JS  Sir , i want a code in javascript for XML database to store details (username and password entered by user during registration process (login process)). please send me a code . Thank you
simple ajax Request and Response code...
simple ajax Request and Response code...  var request=null; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); } if(request
A Simple program
A Simple program  Hi I have written the following code: class FirstRectangle{ public int rectArea(int l,int b){ int farea = l*b... required code: class FirstRectangle{ public int rectArea(int l,int b
simple - JDBC
simple  can we have update,delete,save button in one html or jsp form performing respective operation if yes, give me code respectively.  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp
simple source code for tower of hanoi in android
simple source code for tower of hanoi in android  may I get a source code for tower of hanoi game in android pls.If possible help me as much as possible
query in simple code..i had described all...........
query in simple code..i had described all...........  SAME HERE IF YOU GET THIS PROBLEM SOLVED THEN PLEASE REPLY......... MY ONE JAVA FILE IS: abstract class A { abstract void callmetoo() { System.out.println("anoop
Can anybody help me with this simple MySql code
Can anybody help me with this simple MySql code  select c.countryid, r.bp, r.sp, c.country, t.timee from rate as r, countryloc as c, todaysrate as t where r.countryid=t.countryid and t.countryid=c.country this is waht i gt whn
write simple java code - Java Beginners
write simple java code  Write a program that creates a simple calculator .The user enters two numbers in the text fields, Number 1 and Number 2... the following code: import java.awt.*; import javax.swing.*; import
Simple FTP upload in Java
Simple FTP upload in Java  How to write a program for Simple FTP upload in Java? Any code example of Simple FTP upload in Java will be very helpful for me. Thanks
Simple Login(JSF)
Simple Login(JSF)  I have tried to run the Simple Login code provided using netbeans. It gives me error. CAn I run it using netbeans or need to config anything in order to run the prog
simple javascript validation for numbers
simple javascript validation for numbers  simple javascript validation for register number   Here is a html code that accepts number from the user and check whether the entered value is valid. <html> <head>
WRITE a simple JSP
WRITE a simple JSP  Write a JSP that accepts a string parameter from the browser and simply displays it back in the HTML response   Hi Friend, Try the following code: 1)form.jsp: <html> <form name="form
Need simple java code to start and stop the remote windows service.
Need simple java code to start and stop the remote windows service.  Hi, I Need simple java code to start and stop the remote windows service. Example:There are two servers 1) Server A and 2) Server B. If a notepad.exe file
java spring simple application
java spring simple application  hai I have design a simple application in this I always found class not found exception. I am sendig code as follows please resolve this and send me.my directory structure is as follows Project
Error in simple session bean ..................
Error in simple session bean ..................  Hi friends, i am trying a simple HelloWOrld EJb on Websphere Applicatiopn server 6.1. Can any one plz help me to solve this issue. here is the client code which i have
simple code to login user & authenticate it from database mysql
simple code to login user & authenticate it from database mysql  Sir, I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database. please tell me the code for it. Thanks
Hibernate 4 Simple Example
This section contains a simple Hibernate 4 example using Annotation with source code. The eclipse id and Apache Tomcat is used in this example
A simple question - Java Beginners
A simple question   Design a program to calculate either the square of a number or the square root of a number and display the results. output..., Code to help in solving the problem : import java.io.*; class Square
Need someone to check and modify my simple code - Java Beginners
Need someone to check and modify my simple code   How to write a class that contains Variables that hold hourly rate of pay, number of hours...); } }   Hi Friend, You can use following code: import
Simple Form Controller Example
Example of using Simple Form Controller Page 2 In this page we will see the next steps necessary to run the example code.  Here... it at Example of using Simple Form Controller Step 7: Now we
PHP Registering simple statistics
PHP Registering simple statistics Have you ever wanted to know who visited... ! In this tutorial I will teach you how to make a simple PHP Script that writes... that they visited ! This program follows a simple algorithm as follows: 1. Grab
simple web applications using log4j
simple web applications using log4j  i am getting java.lang.NoClassDefFoundError: org/apache/log4j/Logger and javax.servlet.ServletException: Error... code.............. public class Sample extends HttpServlet { private static
Simple Java Calculator - Java Beginners
Simple Java Calculator  Write a Java program to create simple Calculator for 4 basic Math operations, Addition, Subtraction, Multiplication.... Write proper code for making this calculator operational. Students
Simple Form in Java
Simple Form in Java       This is a simple program of java awt package which constructs a look like... "First Name" and another is the "Last Name". Here is the code
How to write a simple java applet
How to write a simple java applet   Hi, how can i write a simple java applet, displaying text in specific colors and font style. For example... in green color Help me pls :(   Hi Friend, Try the following code
Simple Java Question - Java Beginners
Simple Java Question  [color=#0040BF] Dear All, I have a huge text file with name animal.txt, I have the following sample data: >id1 lion... [/color]  Hi friend, Plz give full source code where you having
Simple HTML example
Simple HTML example In this section we will give you very simple example of a HTML page. After reading this page you should be able to create simple HTML... pages. Creating Simple HTML page Here is simple example of HTML page that displays
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your kind and timely help for the program I have asked... the code for ur kind refernce.. Here it is: EMPLOYEE
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your kind and timely help for the program I have asked... the code for ur kind refernce.. Here it is: EMPLOYEE
Implementing a Simple Event Notifier
Implementing a Simple Event Notifier       In this section, you will learn how to implement a Simple... for implementing a simple event notifier. The Observer class informed the changes
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........  code for a simple java program which performs basic arithmetic operation addition,subtraction
Simple Line Canvas Example
Simple Line Canvas Example       This is a simple example of drawing lines using canvas class... locations and form. In the source code CanvasLine class extends the Canvas class
jQuery To Simple tabs
jQuery To Simple tabs       In this JQuery tutorial we will develop a program  to make simple tabs  Steps to develop the simple tabs . Step 1:        
jQuery to Simple Image Scroller
: Create a new file (simple_carousel.html) and add the following code...jQuery to Simple Image Scroller      ... explanation: The following code includes the jQuery JavaScript library file
Insert Image into Mysql Database through Simple Java Code
Insert Image into Mysql Database through Simple Java Code... simple java code that how save image into mysql database. Before running this java code you need to create data base and table to save image in same database
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
simple code to write an read and write the login detail to a xml file using javascript ( username and password )  pls can nyone give me a code to write and read the login details (username and password )into a xml file using
Simple Date example
Simple Date example       In this section we have presented a simple Date example... is the example code of SimpleDate.java as follows: SimpleDate.java import
Simple Bank Application in JSP
Simple Bank Application in JSP       In this section, we have developed a simple bank.... Download the code and Run the application on browser with the  url. http
Simple Date Format Exception
Simple Date Format Exception       Simple Date Format Exception inherits from a package name... and normalization of date. Simple Date-format provides you to work on choosing any
Simple but confusing code... Parent obj1 = new Parent(); Parent obj2 = new Child();
Simple but confusing code... Parent obj1 = new Parent(); Parent obj2 = new Child();  Hi friends I got confused in the below code snippet: Parent.... Then we create Parent obj2 = new Child(); <--------------- here in this code
Simple Web Application using Servlet
Simple Web Application using Servlet       In this section, we have developed a simple web...://www.roseindia.net/struts/struts2/struts-2-download.shtml. Download the code and Run
Java simple reference source - Java Beginners
Java simple reference source  Hi, please could you recommend me a Java simple reference source (on line or e-book) where I could quickly find... in detail and send me code. Thanks.   Dear friend
Simple Java class program - Java Beginners
Simple Java class program  Hi sir, Please help me Write a simple class that iterates through all the arguments passed in on the command line... your code and handle any errors that may arise. Thank you Alexander 
Simple Java class program - Java Beginners
Simple Java class program  Hello, Please help me, Write a simple class that iterates through all the arguments passed in on the command line... your code Thanx  Hi import java.util.*; import
How to run a simple jsp page in tomcat???
How to run a simple jsp page in tomcat???  i am trying to run a simple jsp page in tomcat,i am having web.xml also in WEB-INF folder. but it is giving me this error below....please help me to solve it. my jsp page code is given
Simple date formatter example
Simple date formatter example       In this section of simple date formatter example we... = formatter.format(todaysDate); Above lines of code formats the date object

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.