Perfect number assistance
Hello,
I'm currently enrolled in a JAVA course and doing very horrible. This course is required for my degree. I have been reviewing the forums and got this far on a program that will ask the user to enter a number and this program will find all the perfect numbers less then the number entered by the user. Here is the code I have so far. Any assistance would be greatly appreciated.
import java.util.Scanner;
public class Stalcup_Robert_6_01_perfect
{//Begin Class
public static void main (String[ ] args)
{//Begin main method
int testNum;
//Create a scanner object for keyboard input
Scanner keyboard = new Scanner(System.in);
//Recieve keyboard entry
System.out.println("Please enter in any number?");
//Hold keyboard entry
testNum = keyboard.nextInt();
}//End Main methhod
public static void factorSum()
int num=1, testNum, elements=0, sum=0, p=0, sum1=0, sum2=0, factors, PrimeNumSequence;
while (num < testNum)
for(int a = 1; a<num; a++)
if(num % a == 0) factors[p++] = a;
int[] factors = new int[elements];
for(int a = 1; a<num; a++)
if(num % a == 0) factors[p++] = a;
for(int a=0; a < factors.length; a++)
if(PrimeNumSequence.isPrime(factors[a]) && factors[a] > 2)
sum1 = factors[a] * factors[a-1];
sum2 = factors[a-1] * 2;
sum2 = sum2 - 1;
if(sum1 == num && sum2 == factors[a])
System.out.println(num + " is a perfect number of " + testNum);
}//End Class
I think what you want to do is to use a recursive method to find out the UNIQUE factors of a number smaller than the given. then check if it is a perfect number. I am thinking you can use either a set or array to collect the factors, then get the sum of the set or array and compare the sum with the number that was factored.
private static Set<Integer> A = new HashSet<Integer>();
public static void primeFactors(int num)
int d;
if (num > 1)
for (d = 2; (num % d) > 0; d++);
A.add(d);
primeFactors(num / d);
}
Similar Messages
-
So far I have
import java.util.Scanner; // program uses class Scanner
public class perfect
// main method begins execution of Java application
public static void main(String args[])
// create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
int number;
int sum;
int calculation;
int i;
calculation = 0;
for ( i = 1; i < number; i = i + 1 ) {
if ( number % i == 0)
calculation = calculation + i;
sum = calculation;
if ( number == sum )
System.out.printf( "d% is a perfect number", number );
else
System.out.printf( "d% is not a perfect number", number );
} // end method main
} // end class perfectBut I get the compile error:
variable number might not have been initialized
for ( i = 1; i < number; i = i + 1 ) {So far I have
import java.util.Scanner; // program uses class
Scanner
public class perfect
// main method begins execution of Java application
public static void main(String args[])
// create Scanner to obtain input from command
nd window
Scanner input = new Scanner(System.in);
int number;
int sum;
int calculation;
int i;
calculation = 0;
for ( i = 1; i < number; i = i + 1 ) {
if ( number % i == 0)
calculation = calculation + i;
sum = calculation;
if ( number == sum )
System.out.printf( "d% is a perfect number",
ber", number );
else
System.out.printf( "d% is not a perfect number",
ber", number );
} // end method main
} // end class perfectBut I get the compile error:
variable number might not have been initialized
for ( i = 1; i < number; i = i + 1 ) {So you need to initialise the variable "number".
int number;You have only declared a variable called number but not given it an initial value. So when you do something like i < number in the loop there is no way to know if i is less than number... -
Need CiscoWorks Part number assistance
I have an education client/school district that would like to renew/upgrade their CiscoWorks licenses to the most current version. The below are the CiscoWorks products that they have:
CiscoWorks Health and Utilization Monitor
CiscoWorks LAN Management Solution 3.1
CiscoWorks QoS Policy Manager 4.0
CiscoWorks Voice Manager 3.1
CiscoWorks VPN/ Security Management Solution 2.3
The customer has 800 devices in their network that need to be managed. What I need are the quantities and Cisco part numbers for this CiscoWorks renewal/upgrade to the most current version. I have found no one in the Midwest region with Cisco that can assist. Any help would be appreciated!HUM and LMS are already at the latest versions as is CVM. Since they already have QPM 4.0, they can go to http://www.cisco.com/upgrade/ and enter their QPM SAS contract number. From there, they can order the QPM 4.1 upgrade.
VMS has been migrated to Cisco Security Manager which is currently at version 3.2. There are a few part numbers there:
CSMST25-3.2-K9 : CS Mgr 3.2 Enterprise Standard - 25 Device Limit Media Kit
CSMST5-3.2-K9 : CS Mgr 3.2 Enterprise Standard - 5 Device Limit Media Kit
CSMPR50-3.2-K9 : CS Mgr 3.2 Enterprise Pro - 50 Device Base Lic Media Kit
Someone from your sales team (i.e. your SE) should know how to contact a network management resource within Cisco to verify exactly what you need. -
I've had my WD external hard drive formatted to MAC OS Extended(Journaled). No issue bout it, all good. I have my old files saved on a desktop hard drive other brand. What specific MacDrive Apps do I need to download on the desktop for me to retrieve my old files back to my external hard drive? Thanks
I've had my WD external hard drive formatted to MAC OS Extended(Journaled). No issue bout it, all good. I have my old files saved on a desktop hard drive other brand. What specific MacDrive Apps do I need to download on the desktop for me to retrieve my old files back to my external hard drive? Thanks
-
Support Phone Number / Assistance Needed
I installed the BOXI server and resgitered it today.
When I add a Crystal report the History, Process, and Schedule tabs are greyed out.
I tryed to call someone but low and behold you do not get to talk to a live person after giving them your money .... my own personal gripe i guess ....
Also i am using the administrator account as well as a domain admin account. (I have it using my AD)
Thanks
ChrisI think the primary cause of this symptom was a bad license key. Can you reach the account rep that gave you the key or was it online?
Also moving to general forum which is for issues like this.
Regards,
Tim -
Hi, i have written a program, i can tell which numbers are perfect, abundant or deficient. i can tell the percentages, and i can tell how many of these numbers i have.
However, i don't know how to get an specific number, for example, if i enter 500, there are 3 perfect numbers, 6, 28, and 496. i need to be able to printout the actual numbers.
public class NumPAD
// instance variables
private int sum; // sum of the factors
private int num; // the number entered
private double perfectCount; // perfect numbers count
private double abundantCount; // abundant numbers count
private double deficientCount; // deficient numbers count
private double total; // sum of all types of numbers
private String name; // the user's name
/**Creates the class object
* @param num user's name
* @param name the user's name
public NumPAD(int num, String name)
// variables are initialized
this.num = num;
this.name = name;
* Returns the sum of the factors
* @return the sum of the factors
public int sumFactors(int num)
sum = 0;
// it creates a for loop, it cannot go past half the numbers entered
for(int i = 1; i <= num/2; i++)
// filters the factors
if(num % i ==0)
// sum gets all the factors and adds them up
sum = sum + i;
return sum;
* Returns the number entered
* @return the number entered
public int getNum()
return num;
* Returns the user's name
* @return the user's name
public String getName()
return name;
* Creates a variable to count the perfect numbers
public void setPerfectCount()
perfectCount++;
* Creates a variable to count the abundant numbers
public void setAbundantCount()
abundantCount++;
* Creates a variable to count the deficient numbers
public void setDeficientCount()
deficientCount++;
* Returns the total of all type numbers
* @return the total of all type numbers
public double getTotal()
total = perfectCount+abundantCount+deficientCount;
return total;
* Returns the perfect count
* @return the perfect count
public double getPerfectCount()
return perfectCount;
* Returns the abundant count
* @return the abundant count
public double getAbundantCount()
return abundantCount;
* Returns the deficient count
* @return the deficient count
public double getDeficientCount()
return deficientCount;
// the test class
import java.util.Scanner;
import java.text.DecimalFormat;
public class NumPADTester
// a class that gets the numbers and percentages of perfect, abundant and
// deficient numbers
public static void main(String[] args)
Scanner input = new Scanner(System.in);
String exit = "1";
// a do-while loop to run until the user's gets bored
do
// asks for the user's name
System.out.println("What is your name? ");
String name = input.next();
System.out.println();
// asks the user to enter a number
System.out.println("Enter a number: ");
int num = input.nextInt();
System.out.println();
// constructor using the user's input
NumPAD howdy = new NumPAD(num,name);
// it creates a for-loop
for(int i = 1; i <= num; i++)
System.out.print(i);
//System.out.println(howdy.getNum());
//System.out.println(howdy.sumFactors(i));
// it gets the perfect numbers
if (i == howdy.sumFactors(i))
System.out.println(" PERFECT");
howdy.setPerfectCount();
// it gets the abundant numbers
else if(i < howdy.sumFactors(i))
System.out.println(" ABUNDANT");
howdy.setAbundantCount();
// it gets the deficient numbers
else
System.out.println(" DEFICIENT");
howdy.setDeficientCount();
System.out.println();
DecimalFormat round = new DecimalFormat("0.##");
System.out.println();
// it gets the percentages of perfect numbers
System.out.println("The percentage of perfect numbers is: "
+ round.format(howdy.getPerfectCount()/howdy.getTotal()*100));
System.out.println();
// it gets the percentages of abundant numbers
System.out.println("The percentage of abundant numbers is: "
+ round.format(howdy.getAbundantCount()/howdy.getTotal()*100));
System.out.println();
// it gets the percentages of deficient numbers
System.out.println("The percentage of deficient numbers is: "
+ round.format(howdy.getDeficientCount()/howdy.getTotal()*100));
System.out.println();
// it gets the amount of perfect numbers
System.out.println("The number of perfect numbers is: "
+(int)howdy.getPerfectCount());
System.out.println();
// it gets the amount of abundant numbers
System.out.println("The number of abundant numbers is: "
+(int)howdy.getAbundantCount());
System.out.println();
// it gets the amount of deficient numbers
System.out.println("The number of deficient numbers is: "
+(int)howdy.getDeficientCount());
System.out.println();
//a do-while loop that asks the user of he/she wants to enter another
// number
do
System.out.print("Do you want to enter another number? (1)Yes, (2)No ");
exit = input.next();
while(!exit.equals("1") && !exit.equals("2"));
System.out.println();
if(exit.equals("2"))
System.out.println("Goodbye " + howdy.getName());
break;
while(exit.equals("1"));
}Any ideas on how to get an specific number??
thanks in advance.Well, i want to the print the numbers, in the regular old way, System.out.print, i dont need an GUI,
i just need for example,
1 deficient
2 deficient
3 deficient
4deficient
5 deficient
6 perfect,
i equals the numbers, so i need to print i alone. this is what i need:
enter a number: <USER ENTERS 6>
then i want to dysplay perfect numbers,
so the program prints out:
"the perfect number(s) is/are: 6
i know i gives me the numbers, but how do i get i out of the loop and print just i?? i know what i need to do, it looks simple in theory, i just dont know how to extract it.
thanks for the support. -
Lenovo G560, Windows 8 and Hiren's Boot program
I installed Windows 8 on my Lenovo G560 and one partition of my Harddisk has some errors. I have tried repairing it with the Windows Repair Utility program but the drive errors continue to occur. Previously when my machine was running on Windows 7, I used the Hiren's Boot 15.1 to repair any harddisk errors. However, since upgrading my laptop to Windows 8, Hiren's seems to fail to work citing time out when trying to read the Harddisk. I have no idea why. I was hoping if anyone has used another version of Hiren's on a Windows 8 that has worked perfectly to assist me. Any help will be much appreciated.
Hi
Welcome To Lenovo Community
We are really sorry to hear about the issue you are facing,
Please try using the Lenovo Hard drive Quick test
http://support.lenovo.com/en_US/detail.page?LegacyDocID=MIGR-70578
You may also refer below thread explaining how to use inbuilt hard disk scan of windows 8
http://www.groovypost.com/howto/windows-8-new-disk-error-checking-feature/
Do give this a try and let us know
Hope This Helps
Cheers!!!
WW Social Media
Important Note: If you need help, post your question in the forum, and include your system type, model number and OS. Do not post your serial number.
Did someone help you today? Press the star on the left to thank them with a Kudo!
If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"!
Follow @LenovoForums on Twitter!
How to send a private message? --> Check out this article.
English Community Deutsche Community Comunidad en Español -
Is there any way to rewrite this query?
Is there room for improvement/rewrite for this query so that it performs well?
select distinct shp_locn
from shp_mstr
where zone = to_char(:b3)
and locn_class = 'r'
and aisle = 'GX-08'
and dock = 'KN'
and locn_id not in (select locn_id from tmp_shp_out_dtl)
order by shp_locnuser659394 wrote:
Alex,
Stop your st_u_pi_d f_u_c__king sarcasm. There were lots of instances like the below thread
where you bring your boring sarcasm to meaningful technical discussions.
If you dont want to answer, just leave it..... you C__u__n__t
Error for a SELECT COUNT ... in stored proc
Alex was giving you perfectly valid assistance.
Your post has now been reported to the moderators as it is completely offensive, unprofessional and unnecessary. -
Having problem with simple variable use in another class
I have a variable made by input from my main class file called upperLimit. I have an external class file in which I would like to use the variable created by the input for upperLimit, but I have forgotten how to go about it. The objective of the program is to output all perfect numbers from 1-upperLimit.
This is my main class:
import java.util.Scanner;
public class Lab13aab
public static void main(String args[])
System.out.print("In the range of [1-10000] what will the upper limit be for analysis? ===> ");
Scanner input = new Scanner(System.in);
int upperLimit = input.nextInt();
System.out.println();
checkToSee isItPerfect = new checkToSee();
int numToCheck;
for(numToCheck=1; numToCheck>=upperLimit; numToCheck++)
isItPerfect.analyze();
}and this is my external class which checks to see if an individual number is a perfect number or not:
public class checkToSee
public void analyze()
int total=1;
int factor;
for(factor=2;factor<upperLimit;factor+
if(upperLimit%factor==0)
total = total + factor;
if(total==upperLimit)
System.out.println(upperLimit + " is a perfect number!");
System.out.println();
}Hy Why ;-)!
Let me guess... you're both new to Java AND Object Orientation? Because you're code (apart from the fact that it is not working) is purely procedural and has nothing to do with object orientation (at least most of it). Have you programmed in C/C++ before?
See the [The Java Tutorial|http://java.sun.com/docs/books/tutorial/java/javaOO/index.html] for more infos...
Greetz, Oliver
Edited by: Trollhorn on Aug 29, 2009 11:02 AM -
Problem concerning parsing int from .dat input
The following program takes information form a ".dat" file, stores it and manipulates it. However, I am having a weird problem. Whenever I try to parse a n int from a certain point in the file (the end of a line) I keep getting thrown a java.lang.NumberFormatException. I understand why this would be thrown if I was sending it a wrong number, but, I am not. In fact the token before the last one sends it the same number and it parses fine. Here is the problem code;
public void getPrice(Scanner scanner)
while(scanner.hasNextLine())
//puts into string the next scan token
String s = scanner.next();
//takes the scan toke above and puts it into an editable enviroment
stringToken = new StringTokenizer(s, " ", false);
while(stringToken.hasMoreTokens())
//moves position within string in file by one
position++;
/*Starts data orignazation by reading from each perspective field
* 1 = day
* 2 = day of month
* 3 = month
* 4 = year
if(position == 1)
String dayFromFile = stringToken.nextToken();
int dayNum = Integer.parseInt(dayFromFile);
System.out.print(days[dayNum-1] +" ");
else if(position == 2)
System.out.print(stringToken.nextToken() + "/");
else if(position == 3)
System.out.print(stringToken.nextToken() + "/");
else if(position == 4)
System.out.print(stringToken.nextToken() +"\n");
//if it is in [buy] area, it prints
else if(position == 8)
String buy = stringToken.nextToken();
System.out.println("Buy: " +buy );
currentBuyPrice = Integer.parseInt(buy);
if(currentBuyPrice < 0)
currentBuyPrice = 0;
if(currentBuyPrice > buyPrice)
buyPrice += currentBuyPrice;
if(currentBuyPrice == buyPrice)
buyPrice +=0;
else
buyPrice -= currentBuyPrice;
//if it is in [sell] area, it prints, and resets the position to zero because line is over
else if(position == 9)
String sell = stringToken.nextToken();
System.out.println("Sell: " +sell);
**currentSellPrice = Integer.valueOf(sell).intValue();;
if(currentSellPrice < 0)
currentSellPrice = 0;
else if(currentSellPrice > sellPrice)
sellPrice += currentSellPrice;
else if(currentSellPrice == sellPrice)
sellPrice +=0;
else
sellPrice -= currentSellPrice;
scanner.nextLine();
position = 0;
if(scanner.hasNextLine() == false)
System.out.println("Net change of buy price: " buyPrice "\n Net change of sell price: " +sellPrice);
//discards all other string areas
else
stringToken.nextToken();
**The problem is here. The string prints as a perfect number, no spaces or anything. I thought it could be because the number was "-1" but I tried it without the "-" and it still threw the same thing. The really weird thing is that the buy code works fine, and it parses all ints I send it fine.
EDIT:
Here is how the .dat looks;
1 5 15 2006 18 26 12 -1 -1
1 5 15 2006 18 32 20 -1 -1
1 5 15 2006 18 38 29 -1 -1
It is the last "-1" that can not be parsed. I tried putting an excape character at the end so it looked;
1 5 15 2006 18 26 12 -1 -1 &
1 5 15 2006 18 32 20 -1 -1 &
1 5 15 2006 18 38 29 -1 -1 &
That did nothing.import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class CSE extends JFrame implements ActionListener
//GUI COMPONENTS
JTextField input = new JTextField(20);
JButton submit = new JButton("submit");
//COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
Calendar calSource = Calendar.getInstance();
int day = calSource.get(Calendar.DAY_OF_MONTH);
int month = calSource.get(Calendar.MONTH);
int year = calSource.get(Calendar.YEAR);
int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
int dayS;
int monthS;
int yearS;
//if there is file found
boolean proceed = false;
//int data for analysis
int buyPrice;
int currentBuyPrice;
int sellPrice;
int currentSellPrice;
//toold for parsing and decoding input
String inputS = null;
String s = null;
StringTokenizer stringToken = null;
Scanner scanner;
int position = 0;
public CSE()
super("Test CSE");
setDefaultCloseOperation(EXIT_ON_CLOSE);
input.setBackground(new Color(0, 80, 250));
submit.addActionListener(this);
getContentPane().add(input, BorderLayout.SOUTH);
getContentPane().add(submit, BorderLayout.NORTH);
setSize(500, 500);
setVisible(true);
public void actionPerformed(ActionEvent e)
getMonth();
inputS = input.getText();
FileReader newRead = null;
try {
newRead = new FileReader(monthS +"-" +day +"-" +year +"/" +inputS +".dat");
proceed = true;
catch(FileNotFoundException f)
System.out.println("File not found");
proceed = false;
if(proceed)
BufferedReader bufferedReader = new BufferedReader(newRead);
scanner = new Scanner(bufferedReader);
scanner.useDelimiter("\n");
getPrice(scanner);
public void getPrice(Scanner scanner)
while(scanner.hasNextLine())
//puts into string the next scan token
String s = scanner.next();
//takes the scan toke above and puts it into an editable enviroment
stringToken = new StringTokenizer(s, " ", false);
while(stringToken.hasMoreTokens())
//moves position within string in file by one
position++;
/*Starts data orignazation by reading from each perspective field
* 1 = day
* 2 = day of month
* 3 = month
* 4 = year
if(position == 1)
String dayFromFile = stringToken.nextToken();
int dayNum = Integer.parseInt(dayFromFile);
System.out.print(days[dayNum-1] +" ");
else if(position == 2)
System.out.print(stringToken.nextToken() + "/");
else if(position == 3)
System.out.print(stringToken.nextToken() + "/");
else if(position == 4)
System.out.print(stringToken.nextToken() +"\n");
//if it is in [buy] area, it prints
else if(position == 8)
String buy = stringToken.nextToken();
System.out.println("Buy: " +buy );
currentBuyPrice = Integer.parseInt(buy);
if(currentBuyPrice < 0)
currentBuyPrice = 0;
if(currentBuyPrice > buyPrice)
buyPrice += currentBuyPrice;
if(currentBuyPrice == buyPrice)
buyPrice +=0;
else
buyPrice -= currentBuyPrice;
//if it is in [sell] area, it prints, and resets the position to zero because line is over
else if(position == 9)
String sell = stringToken.nextToken();
System.out.println("Sell: " + sell);
currentSellPrice = Integer.valueOf(sell).intValue();;
if(currentSellPrice < 0)
currentSellPrice = 0;
else if(currentSellPrice > sellPrice)
sellPrice += currentSellPrice;
else if(currentSellPrice == sellPrice)
sellPrice +=0;
else
sellPrice -= currentSellPrice;
scanner.nextLine();
position = 0;
if(scanner.hasNextLine() == false)
System.out.println("Net change of buy price: " +buyPrice +"\n Net change of sell price: " +sellPrice);
//discards all other string areas
else
stringToken.nextToken();
public void getMonth()
for(int x=0; x < monthCheck.length; x++)
if(month == monthCheck[x])
monthS = (x+1);
x = monthCheck.length;
public static void main(String [] args)
CSE cs = new CSE();
}Make a folder named whatever the current date is, and put a .dat file in there with this;
1 5 15 2006 0 3 52 -1 -1
1 5 15 2006 0 29 52 -1 -1
1 5 15 2006 0 36 1 -1 -1
1 5 15 2006 0 42 9 -1 -1
1 5 15 2006 0 48 18 -1 -1
1 5 15 2006 0 54 29 -1 -1
1 5 15 2006 1 0 37 -1 -1
1 5 15 2006 1 6 44 -1 -1
1 5 15 2006 1 12 53 -1 -1
1 5 15 2006 1 19 1 -1 -1
1 5 15 2006 1 25 9 -1 -1
1 5 15 2006 1 31 18 -1 -1
1 5 15 2006 1 37 27 -1 -1
1 5 15 2006 1 43 37 -1 -1
1 5 15 2006 1 49 46 -1 -1
1 5 15 2006 1 55 53 -1 -1
1 5 15 2006 2 2 1 -1 -1
1 5 15 2006 2 8 10 -1 -1
1 5 15 2006 2 14 27 -1 -1
1 5 15 2006 2 20 37 -1 -1
1 5 15 2006 14 12 45 -1 -1
1 5 15 2006 14 20 36 -1 -1
1 5 15 2006 14 26 44 -1 -1
1 5 15 2006 14 32 52 -1 -1
1 5 15 2006 14 39 0 -1 -1
1 5 15 2006 14 45 8 -1 -1
1 5 15 2006 14 51 17 -1 -1
1 5 15 2006 14 57 26 -1 -1
1 5 15 2006 15 3 35 -1 -1
1 5 15 2006 15 9 43 -1 -1
1 5 15 2006 15 15 51 -1 -1
1 5 15 2006 15 21 59 -1 -1
1 5 15 2006 15 28 6 -1 -1
1 5 15 2006 15 34 15 -1 -1
1 5 15 2006 15 40 24 -1 -1
1 5 15 2006 15 46 33 -1 -1
1 5 15 2006 15 52 40 -1 -1
1 5 15 2006 15 58 48 -1 -1
1 5 15 2006 16 4 56 -1 -1
1 5 15 2006 16 11 5 -1 -1
1 5 15 2006 16 17 14 -1 -1
1 5 15 2006 16 23 24 -1 -1
1 5 15 2006 16 29 32 -1 -1
1 5 15 2006 16 35 39 -1 -1
1 5 15 2006 16 41 47 -1 -1
1 5 15 2006 16 47 55 -1 -1
1 5 15 2006 16 54 4 -1 -1
1 5 15 2006 17 0 13 -1 -1
1 5 15 2006 17 6 23 -1 -1
1 5 15 2006 17 12 31 -1 -1
1 5 15 2006 17 18 39 -1 -1
1 5 15 2006 17 24 46 -1 -1
1 5 15 2006 17 30 55 -1 -1
1 5 15 2006 17 37 3 -1 -1
1 5 15 2006 17 43 12 -1 -1
1 5 15 2006 17 49 20 -1 -1
1 5 15 2006 17 55 29 -1 -1
1 5 15 2006 18 1 36 -1 -1
1 5 15 2006 18 7 44 -1 -1
1 5 15 2006 18 13 53 -1 -1
1 5 15 2006 18 20 2 -1 -1
1 5 15 2006 18 26 12 -1 -1
1 5 15 2006 18 32 20 -1 -1
1 5 15 2006 18 38 29 -1 -1
1 5 15 2006 18 44 36 -1 -1
1 5 15 2006 18 50 45 -1 -1
1 5 15 2006 18 56 54 -1 -1
1 5 15 2006 19 3 3 -1 -1
1 5 15 2006 19 9 10 -1 -1
1 5 15 2006 19 15 18 -1 -1
1 5 15 2006 19 21 26 -1 -1
1 5 15 2006 19 27 34 -1 -1
1 5 15 2006 19 33 44 -1 -1
1 5 15 2006 19 39 53 -1 -1
1 5 15 2006 19 46 3 -1 -1
1 5 15 2006 19 52 12 -1 -1
1 5 15 2006 19 58 20 -1 -1
1 5 15 2006 20 4 30 -1 -1
1 5 15 2006 20 10 38 -1 -1
1 5 15 2006 20 16 50 -1 -1
1 5 15 2006 20 23 0 -1 -1
1 5 15 2006 20 29 9 -1 -1
1 5 15 2006 20 35 17 -1 -1
1 5 15 2006 20 41 24 -1 -1
1 5 15 2006 20 47 32 -1 -1
1 5 15 2006 20 53 40 -1 -1
1 5 15 2006 20 59 49 -1 -1
1 5 15 2006 21 5 59 -1 -1
1 5 15 2006 21 12 8 -1 -1
1 5 15 2006 21 18 16 -1 -1
1 5 15 2006 21 24 23 -1 -1
1 5 15 2006 21 30 31 -1 -1
1 5 15 2006 21 36 40 -1 -1
1 5 15 2006 21 42 49 -1 -1
1 5 15 2006 21 48 57 -1 -1
1 5 15 2006 21 55 5 -1 -1
1 5 15 2006 22 1 12 -1 -1
1 5 15 2006 22 7 20 -1 -1
1 5 15 2006 22 13 28 -1 -1
1 5 15 2006 22 19 38 -1 -1
1 5 15 2006 22 25 48 -1 -1 -
If anyone could help me write this thing using simple loops I swear i would dance at there wedding. This is my last class to graduate college with a bachelors and I am so computer stupid. If anyone could write out this code for me or just help me get started with my main method i would appreciate it so much. The java problem that I have to write a program to is below and I am sorry it is alot of question to a novice programmer like myself I am so lost please help!!!!!!!!!!!!!
Write a java class called factorNumber that gets a whole number from the user and determines its divisors. It should return the results in a dialog box with a message like: The factors of 25 are 1,5,25.
Place this code in a large loop so the user can check as many numbers as they like. Also put in error checking. If the user enters a nonpositive iteger, give them an error message and prompt for another number. If at any point the user clicks on the cancel button for any dialog box exit the program.
When that is working, add more fuctionality to your program. Check the given number for the following conditions.
1.prime number(only divisible by 1 and itself. 1 is not considered to be prime.)
2.perfect number(it is the sum of its factors up to but not including itself; ex" 6 is a perfect number because its factors are 1,2,3 and 1+2+3=6.
3.perfect square(it is the square of some other whole number)
if any of these conditions are satisfied, include that information in the message to the user. Respond with message:
The factors of 25 are 1,2,25
25 is a perfect square.
or
the factors of 6 are 1,2,3,6.
6 is a perfect number.
I Ammmmmm so lost how do i white this thing????????????/i hope i can get something out of this:
import java.io.*;
class FactorNumber
public static void main(String[] args)
int base = 0;
int y=0;
double z;
float w;
try{
System.out.println("Enter the base : \t " );
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
base = Integer.parseInt(br1.readLine());
System.out.println("the factors are:");
for(int x=1;x<=base; x++ ){
if(base%x==0){
System.out.print(x+" ");
y=y+x;
if(y==base){System.out.println("\nThis is a perfect number");}
z = Math.sqrt(base);
w=Math.round(z);
if(z%w==0){
System.out.println("\n"+base+ " is a perfect square");
}catch (IOException e){System.out.println("The error" + e);}
} -
Baffled by code....
Can anyone help me out here? I've been over this code for the last hour and still can't figure out what's going wrong with it. It's supposed to take integers from 1 to 1000 and find integers that are perfect numbers (A numbers factors added together equal the original number). For some reason it's only outputing the first number and then stops. Any help would be greatly appreciated.
//Java core packages
import java.awt.*;
//Java extension package
import javax.swing.*;
public class Assign3_3097 extends JApplet {
int FinalSum;
public void init()
//JTextArea to display results
JTextArea outputArea = new JTextArea();
//get applet's content pane
Container container = getContentPane();
//attach outputArea to container
container.add( outputArea );
int result; //store value of call to method
String output = ""; //String containing results
for ( int number = 1; number <= 1000; number++)
result = perfect (number);
if (result > 0 )
//append result to String output
output += result + " is a perfect number\n";
}//end for loop
outputArea.setText( output );//puts results in JTextArea
} //end method init
//perfect method declaration
public int perfect( int x )
int value;
for ( int divisor = 1; divisor <= 500; divisor++ ){
value = x % divisor;
if ( value == 0 )
FinalSum = FinalSum + divisor;
}//end for loop
if ( FinalSum == x)
return x;
else
return 0;
}//end perfect method
} //end class Assign3_3097hi,
umm, well i can see quite a few mistakes in the code due to which ur program is not working, now as u must be knowing a perfect number is those numbers which are the sum of their positive proper divisors.. for eg
6 = 1 + 2 + 3
now if that is the case, there is a major flaw
for ( int divisor = 1; divisor <= 500; divisor++ ){why would u want to divide the number till 500 ???
should read
for ( int divisor = 1; divisor < x; divisor++ ){also, the variable
>int FinalSum; which is declared globally must be declared locally for otherwize it will retain itz previous values.
ie
public int perfect( int x )
int value;
int FinalSum = 0;now if you change that ur code will start working fine,
ps: Your program will work faster if you replace the "output" from String type to StringBuffer.
cheerz
ynkrish -
I Have been chatting to the customer care (Case number tel:0214257546) i have photoshop cs5 extended wigh serial numbers for windows and mac. There is no doenload appliaction when i try load onto the mac, works perfectly on a windows machine.
the Customer care have suggested I login to the LWS website and try that way. But when I go there it says I'm an unauthorized user and does not give me the option to login at all.
I Would really appreciate assistance with thisDownloads available:
Suites and Programs: CC 2014 | CC | CS6 | CS5.5 | CS5 | CS4 | CS3
Acrobat: XI, X | 9,8 | 9 standard
Premiere Elements: 13 | 12 | 11, 10 | 9, 8, 7 win | 8 mac | 7 mac
Photoshop Elements: 13 |12 | 11, 10 | 9,8,7 win | 8 mac | 7 mac
Lightroom: 5.7.1| 5 | 4 | 3
Captivate: 8 | 7 | 6 | 5
Contribute: CS5 | CS4, CS3
Download and installation help for Adobe links
Download and installation help for Prodesigntools links are listed on most linked pages. They are critical; especially steps 1, 2 and 3. If you click a link that does not have those steps listed, open a second window using the Lightroom 3 link to see those 'Important Instructions'. -
My iPhone 4 cellphone was stolen last year. I have done all the procedures of reporting it to the South African Police Services and my Vodacom service provider. I do have the case number and I did blacklist my stolen phone. I have not had any assistance. I had installed Find My iPhone but did not have any iCloud account on it (ie. iCloud Username and Password). So I am unable to track it or find its location as yet. Please help me find my iPhone 4.
Your only chance is setting it up as new device without using the latest backup afterwards, which you already did.
If this does not work, you should get it serviced:
Apple - Support - Service Answer Center
How to back up your data and set up as a new device -
I can't find a specific answer to this question.
I did have a functioning Windows 8 installation on my MacBook Pro previously. I tried to make a third exFAT partition so as to have a drive mutually readable/writable to both operating systems. This made it so I could no longer boot into my Windows installation.
I know I'll need the boot camp drivers installed on the Windows installation after the fact, but would manually creating a partition and installing the OS without Boot Camp Assistant work? And would I be able to boot from it while having a total of 3 partitions?That's the spirit!
Just be sure to have your OS X junk safe in a tested backup, in case the whole thing craps out and you end up having to do a low-level partition and erase of the entire drive.
And like I said, the problem is not OS X. I've set up mine at least once with 4 partitions holding as many flavors of OS X as can run on the hardware, all perfectly bootable on demand.
Maybe you are looking for
-
Receive zipfile with sender file adapter
Hello, I need to receive one zipped file (binary data) with the file sender adapter. This zipped file contains an xml file that I need to process. What is the best way to do this? I have looked into writing an adapter module to unzip or base64 encode
-
Links in PDF's and Excel have stopped working
I'm using a fresh install of Firefox 14.0.1. Links in PDF's and Excel have stopped working (the reinstall was part of the problem solving). FF is my default browser.
-
IiPod serial number stored in iTunes, can anyone advise how I find this information for my insurance company?
-
Lightroom won't start after 6 mos of use
After turning on my computer this morning I can't get Lightroom back up. I get the following message Any help would be truly appreciated
-
when i merge to HDR my photo will not save, in fact my file menu will not open up. what am i doing wrong? it used to work.I have Photoshop cs5