i dont no how to solve it pls

Ads
 

i dont no how to solve it pls

Calculate and display the sum of all prime number from 1 to 100 covert in java system codes

View Answers

December 15, 2010 at 3:38 PM

Hi Friend,

Try the following code:

class PrimeNumbers{
public static void main (String args[]){
String primeNo = "";
int sum=0;
int j=0;
System.out.println("Prime nums are:" );
for (int i = 1; i < 100; i++){ {
for ( j = 2; j < i; j++){
if (i % j == 0) {
break;
}
}
if (i == j) {
primeNo += i + " ";
sum+=i;
}
}
}
System.out.println(primeNo);
System.out.println("Sum of Prime Numbers: "+sum);
}
}

Thanks


December 27, 2010 at 4:54 PM

Hi friend Try this code.......

import java.io.;
class today2
{
public static void main(String args[])throws IOException
{
BufferedReader obg=new BufferedReader(new InputStreamReader(System.in));
String str=obg.readLine();
int num=Integer.parseInt(str);
int sum=0;
//int  test=5;
       for(int i=2;i&lt;=num;i++)
                {
     if(num%i==0)
             {
      sum=sum+i;
              }
     }
System.out.println("Result"+sum);
}
}

Ads









Related Tutorials/Questions & Answers:
i dont no how to solve it pls
i dont no how to solve it pls   Calculate and display the sum of all prime number from 1 to 100 covert in java system codes
PureStack question---i dont know how to do this
PureStack question---i dont know how to do this  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from... the queue g. H and I join the queue h. G leaves the queue i. H and I leave
Advertisements
PureStack question---i dont know how to do this
PureStack question---i dont know how to do this  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from... the queue g. H and I join the queue h. G leaves the queue i. H and I leave
how do i solve this problem?
how do i solve this problem?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access
how do i solve this question?
how do i solve this question?  1.Define a class named Circle with the following properties: a) An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier
how should i can solve
how should i can solve  Web based program - Input - Person's contact details with Passport Number as Unique Key. Save data in to oracle / MySQL. Output - List of Persons saved in the database. Technology to be used - JSP
one error but i dont know how to fix it o_O!!!
one error but i dont know how to fix it o_O!!!  where is the mistake here ?? import java.utill.Scanner; public class Time { public static void main (String [] args) { Scanner keyboard = new Scanner (System.in
how can i get output pls urget tell me
how can i get output pls urget tell me  HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
how to solve
how to solve   log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources). log4j:WARN Please initialize the log4j system properly
how to solve this..
how to solve this..  Given a list of students and their marks Name | Science | Math | English | Computer Ahmad | 28 | 100 | 66 | 34 Samad | 56 | 89 | 55
how to solve this..
how to solve this..  Given a list of students and their marks Name | Science | Math | English | Computer Ahmad | 28 | 100 | 66 | 34 Samad | 56 | 89 | 55
pls i need help with my assignment
pls i need help with my assignment  how to write a code that ask the user for the height of the triangle and prints the triangle using * eg if height is 3 it prints * and also using import java.util.Scanner
i need help to solve this problem
i need help to solve this problem  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input.... H and I join the queue h. G leaves the queue i. H and I leave the queue
how to solve an internet connection problem
how to solve an internet connection problem  when i run my..." java.lang.UnsupportedOperationException: Not yet implemented the problem is that i don`t know how to implement
How to solve the Hibernate Common Exceptions?
How to solve the Hibernate Common Exceptions?  How to solve the Hibernate Common Exceptions
how to solve this problem for oracle connectivity
how to solve this problem for oracle connectivity  Exception in thread "main" java.sql.SQLException: Io exception: The Network Adap ter could not establish the connection
how to solve 'Stop Running This Script' Error ?
how to solve 'Stop Running This Script' Error ?  Hi.. When opened the page on IE browser(version : 8.0),it gives an java script error (i.e.Stop Running This Script). I have used jsp/servlet for this. Please help to resolved
how to solve this kind of error in Eclipse IDE?
how to solve this kind of error in Eclipse IDE?   i'm creating the Simple CRUD Using Jsp, Servlet and MySQL program and i'm using the eclipse, and i all most done it, finally i'm going to run myself, it can't be run. i
i have a problem to do this question...pls help me..
i have a problem to do this question...pls help me..  Write a program... reversedNumber = 0; for (int i = 0; i <= num; i...; reversedNumber = reversedNumber * 10 + r; i = 0
Solve it
Solve it  How to calculate the value which contains oparator and operand both using command line argument
Small Bug How to solve in my code
Small Bug How to solve in my code  String season=""; pst = con.prepareStatement("SELECT DISTINCT(Season) season FROM specialdates where Regid...") + ","; it shows bug in findbugs tool.. but it executes successfully how to solve
solve this pbm
solve this pbm  sir rows are also inserting i have checked in the database also the rows are not affected in the table . The first pbm wich i have sent to you is not yet solved.......... pls give me detail explaination how we
How can we solve this puzzle using java ?
How can we solve this puzzle using java ?  Sachin likes sweets a lot...*3= 9 Hence total cost will be 1+6+4+18+15+9=53 What I have tried: class A { static void printSubsets(int set[]) { int n = set.length; for (int i = 0; i
i want to retriev and update in same form but its not working pls help....
i want to retriev and update in same form but its not working pls help....  <p><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html></p> <p>
how to make a matrix like datagrid in ide in java pls help
how to make a matrix like datagrid in ide in java pls help  how to make a datagrid mainly matrix in ajava standalone app
solve this
solve this   Create a student class. The student object should have studentid, studentname, subject and marks as properties. Also generate the getter and setter methods. Create 5 objects of this class and populate values
Want to add a resource in the build directory that's created when i run an mvn assembly:assembly command. Pls help!
Want to add a resource in the build directory that's created when i run an mvn assembly:assembly command. Pls help!  I have got a certificate in my resource folder-> src/main/resources/cacerts. When I do a mvn assembly
How to add dynamically rows into database ?Need help pls
into the database.I have been trying to solve in for ages.Can anyone pls help me.Thanks...How to add dynamically rows into database ?Need help pls  Hi everyone, I really have a problem of insert multiple rows into the database.Now i can
how to solve error like'java.lang.NumberFormatException: For input string: "7600113411"' this
how to solve error like'java.lang.NumberFormatException: For input string: "7600113411"' this  java.lang.NumberFormatException: For input string: "7600113411"    java.lang.NumberFormatException: For input string
Am using windows xp os..how to install wamp server for this os ?i have a trouble in this..
Am using windows xp os..how to install wamp server for this os ?i have a trouble in this..  i installed wamp server . i was put my wampserver is online.. but i cant open phpmyadmin in my browser. i dont know the reason.. pls
How do I upgrade mysql?
How do I upgrade mysql?  How do I upgrade mysql

Ads