Factors Of Number Up To 10

Apr 2, 2015

Finding Factors of Numbers up to 10, but ending with infinite loop

class Factors
{
public static void main(String arg[]) {
int i,j;
for(i=1;i<=10;i++){
System.out.println("Factors of " + i + " are: ");
for(j=1;j<=i;i++) {
if(i%j ==0) System.out.print(j+" ,");
}
}
}
}

View Replies


ADVERTISEMENT

Calculate The Factors Of A Positive Integer Number

Mar 16, 2014

lines 7, 8, &12 "primes" are underline in red (prime cannot be resolved) is what pops up when i hover over the x's.

i don't get why that is.

package assignment7;
public class Exercise3
{
public static void main(String[] args)
{
Prime.setSize(1000);
for (int p = Primes.next(); p < 30; p = Primes.next())

[Code]...

View Replies View Related

Calculate Factors Of Positive Integer Number

Mar 17, 2014

Lines 7, 8, &12 "primes" are underline in red (prime cannot be resolved) is what pops up when i hover over the x's.

I don't get why that is.

Java Code :

public class Exercise3
{
public static void main(String[] args) {
Prime.setSize(1000);
for (int p = Primes.next(); p < 30; p = Primes.next()) {
int n = (int)Math.round(Math.pow(2,p)) - 1;
System.out.printf("%d 2^%d-1%d", p, p, n);
if (Primes.isPrime(n))

[Code] ....

View Replies View Related

Java GUI ActionListener - Determine Factors Of Input Placed At Number Text Field

Oct 12, 2014

I just started Java a few days ago and I'm having trouble with ActionListener..

Here are my codes so far , i'm having trouble with the

btnDetermineAction10686696_842067395825457_2521361553839739125_n.jpg:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class NumberAnalyzer extends JFrame{
private JButton btnDetermine, btnClear;
private JTextField txtNumber, txtFactors, txtPrime;
private JLabel lblNumber, lblFactors, lblPrime;
private JPanel pnlNumber, pnlNumber1,

[Code] ....

The output should be the one in the picture:

Input is placed at the NUMBER text field.

Identify its factors, write it at FACTORS text field.

Determine if it is prime. If prime, output at PRIME text field is “Yes”, “No” otherwise.

View Replies View Related

Loading Winning Saved File - All Numbers Have Unique Set Of Prime Factors

Nov 7, 2014

The game doesn't seem to be working but you can win by loading a winning saved game.

Hint: Remember that all numbers have a unique set of Prime Factors.

I have been struggling to solve this. The code is not in error. I am trying to load a winning file but unable to solve.

Here is the java code:

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
public class Main {
static final int GAME_SIZE = 40; //Disk sizes go from 0->39
 // Produce a list of the first N prime numbers

[Code] ....

Results:

C:UsersSal_2>java Main
Welcome to Towers of Toast!!!
Type 'new' to start a new random puzzle
Type 'load' to load a saved puzzle
new
[0, 2, 3, 4, 5, 6, 8, 10, 14, 19, 20, 25, 26, 28, 35, 38, 39]
[7, 9, 11, 13, 15, 21, 22, 23, 27, 31, 32]
[1, 12, 16, 17, 18, 24, 29, 30, 33, 34, 36, 37]
|
|
XX |
|
XXX |
|
XXXX |
|
XXXXX |
|
XXXXXX |
X
XXXXXXXX XXXXXXX
XXXXXXXXXXXX
XXXXXXXXXX XXXXXXXXX
XXXXXXXXXXXXXXXX
XXXXXXXXXXXXXX XXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The game is broken! We saved your game, though. Here are your save game numbers:

146209709250387100944095470
52067710192022655041
21882855117530023387473

C:UsersSal_2>java Main
Welcome to Towers of Toast!!!
Type 'new' to start a new random puzzle
Type 'load' to load a saved puzzle
load
Enter save number for pole 1:
3
Enter save number for pole 2:
1
Enter save number for pole 3:
11
Exception in thread "main" java.lang.RuntimeException: Not all disks accounted f
or
at Main.main(Main.java:100)

C:UsersSal_2>

View Replies View Related

Program That Asks User For Integer And Prints Out All Its Factors In Increasing Order

Nov 18, 2014

Write a program that asks the user for an integer andthen prints out all its factors in increasing order. Use a class FactorGenerator with a constructor FactorGenerator(int numberToFactor) and methods nextFactor and hasMoreFactors. Supply a class FactorTester whose main methods reads a user input, constructs a FactorGenerator object and prints the factors.

Here is what I have so far for my main class and tester class

public class FactorGenerator
{
int factor;
int number;
int x;
FactorGenerator(int numberToFactor)
{
number = numberToFactor;
}

[Code]....

View Replies View Related

Number Guessing Program - Computer Guesses A Number That User Is Thinking Of Within Certain Range

Mar 28, 2015

I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.

-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:

Welcome to this first-ever mind-guessing program!

Please pick a range (higher than 1 and no larger than 50): 32

You will choose a number between 1 and 32... and I will try to guess it.

With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.

-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:

My fourth guess is 17: h
My guess is too high?

My fifth guess is 16: h
*** I am unlucky this round. I give up.

Let's play!

My first guess is 10:
etc..

import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;

[Code] ....

View Replies View Related

User Enter 5 Digit Number And In Return List Each Number On Their Respective Lines

Sep 16, 2014

So I am currently writing my first assignment and have run into problems with my coding. The task was to have someone enter a 5 digit number and in return, I list each number on their respective lines. We also must create an error if a number other than 5 digits was entered. My problem is that when they enter a 1 or 2,3,4,6,7,8 digit number.. the error message occurs along with the rest of the messages (listing the numbers, etc). I want the program to end (or even re-ask to enter the numbers) if they incorrectly enter the data.

View Replies View Related

Program That Takes A User Inputted Number And Converts It To A Binary Number

May 5, 2014

trying to write a program that takes a user inputted number and converts it to a binary number.

Here's what I have:

package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();

[Code]...

Bugs on:

Line 13
Line 17
Line 23

View Replies View Related

Calculate Total Length Of N Number Of Bamboo Trees In M Number Of Seasons

Feb 20, 2014

In a forest, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons. The season always starts with winter.

import java.util.Scanner;
public class Tree {
public static void main(String args[]) {
int length;
int season;

[Code] ....

View Replies View Related

Compute Recursively Total Number Of Blocks In Triangle With Given Number Of Rows

Jul 8, 2014

We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.

triangle(0) → 0

triangle(1) → 1

triangle(2) → 3

View Replies View Related

Creating Method That Prints The Square Root Of A Number Up To A Certain Number?

Feb 27, 2015

I am trying to create a method that prints the square root of a number up to a certain number. It needs to take a single int parameter for example "n" , and then print all of the (positive) even perfect squares less than n, each on a separate line. I want the method to be called something like this:

public void Squares(int n) {
}

I need the output to look something like this:

Example: if n = 40, your code should print

4
16
36

So I have been working for a few hours now and am really stuck.

This is what I have so far:

int count = 0;
int n = 4;
int max = n;
while(count < max) {
System.out.println(n);
n = n * n;
count++;

View Replies View Related

Program Is To Accept Number And Display New Number After Removing All Zeros

Dec 29, 2014

ex
Sample input:2340980
Sample Output:23498

this is the program i have tried but is dosent work

import java.util.*;
class zero
{
public static void main(String args[])
{

[Code]....

View Replies View Related

How To Create Simple Random Number Generator For Number Between 1 -10

May 18, 2015

I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.

View Replies View Related

I/O Arrays - Count Number Of Repetitiveness In String For The Number

May 19, 2014

//read the file
//make the numbers 1 string line
//count the number of repetitiveness in the string for the numbers
//display four lowest ones

import java.io.*;
import java.util.*;
public class Lottery2

[Code] ....

when I run it the array gets sorted but how do i keep the data in other words

what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.

View Replies View Related

Change Negative Number To Positive Number?

Nov 20, 2014

I am 4 weeks into my Intro to Java course and I am having a bit of trouble with my code. I need to make a program that will take a user inputted number, space the numbers out, then add them to a total sum. What I am having a hard time with is when I enter a negative number. I can't figure out what I need to do to have my program ignore the "-" in the string.

import java.util.*;
public class Week4_Programming_Problem
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
int number, digit, sum=0;
char digitPos;

[code]....

View Replies View Related

Store A Number Of Different Value Cards For A Number Of Players?

Feb 18, 2014

i am trying to store a number of different value cards for a number of players. E.g there can be 2 , 4 or more players and each player can have any number of cards.

I have decided to use an arraylist for cards and tried using an array for players. But after coding and reading some information online, i realised that it is not possible to have an array of arraylist.

View Replies View Related

Java Lotto - Randomly Generate Five-digit Number And Prompts User To Enter Five-digit Number

Sep 25, 2014

1. Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:

- The user wins the first prize if the user input matches all five digits in the lottery number in exact order.
-The user wins the second prize if the user input matches any four digits in the lottery number in exact positions.
-The user wins the third prize if the user input matches any three digits in the lottery number in its exact position.
-The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position.

- The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.here is my code. I have tried replacing the && statements with || and it always returns either case 1 or case default.

import java.util.Scanner;
import java.util.Random;
class Hw5 {
static int getPrize(int g1, int g2, int g3, int g4, int g5,
int u1, int u2, int u3, int u4, int u5) {

[code]...

View Replies View Related

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

View Replies View Related

How To Get Rid Of Last Repeated Number

Mar 3, 2015

So i created a method that basically similar to Math.pow, but using recursion.However, it works fine except it prints the final result twice, how do i get rid of the last repeated number ? here is my method :-

public static int recursion(int base, int degree) {
if (degree > 0) {
base = base * recursion(base, degree - 1);
System.out.println(base);

[code]....

how do i get rid of that last repeated 81 ?

View Replies View Related

Display All Odd Number Between 1 And 15

Nov 16, 2014

Write a program that will display all the odd number between 1 and 15. here is the code that i use :

Scanner scan = new Scanner (System.in);
int i, num=0, count_odd = 0;
for(i=1; i<=15; i++) {
System.out.println("please enter number ");
num = scan.nextInt();

[Code] ....

View Replies View Related

Can't Print Number

Oct 14, 2014

I can't print the number that is supposed to come out

public class Skateboard {
private int wheels = 4;
private int trucks = 2;
private int bearings = 8;
private int gripTape = 1;
 
[code]....

How come sb1.assembly() doesn't return the values? :/

View Replies View Related

Printing Out Value Of Each Number

Jan 10, 2015

I finally got this to work but only by printing out the value of each number to debug as such, was there an easier way to do it that I missed?

public class Statistics { 
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// variables used
double num1;
double num2;
double num3;
double num4;
double num5;
double num6;
Scanner input = new Scanner(System.in);
//receive number and add it separately

[Code] ....

View Replies View Related

How To Check If At Least One Number In A String Is Different From 0

Nov 18, 2014

I'm trying to come up with a method that would validate each turn a player makes. For a turn to be valid, it has to only contain numbers from 0 to 3(inclusive) and at least one digit must not be 0. Here is what I`ve come up with so far. For example, with "303" as the number and "101" as the turn, the turn would be valid and my method should return true, but it does not.

public static boolean turnIsValid (String number, String turn ){
boolean rep=false;
int pos1=0;
char min='0';
char max='3';
while(number.length()==turn.length()&&pos1<turn.length()){

[Code] ....

View Replies View Related

How To Initialize To First Number Entered

Aug 10, 2014

initialize the min and max to be the first numbers entered, need to improve the code, because if the number entered is < 0 there is an error. but i dont understand how i would initialize to the first number entered, my understanding is tha if the user enters a 5 , then i should initialize to value 5, but i cant anticipate what the user will enter. I could initializa to null, but that still is not the first number entered.

int min = 0;
int max = 0;
int option = JOptionPane.YES_OPTION;
while ( option == JOptionPane.YES_OPTION){

[code]....

View Replies View Related

Calculating Factorial Of Int Number

Mar 2, 2014

I'm working on some exercises and I'm having some problems with a method. I want to create a method to calculate the Factorial of an int number. I already wrote code that asks the user to input an int number and it calculates the Factorial, and it works fine

i.e.: if I input 5 it outputs

5! = 120

as it should. Here's the code:

import java.util.Scanner;
public class Factorial1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int total = 1;
 
[Code] ....

Now I want to make a method to re-use this code in other programs and I wrote this program:

public class TestClass {
public static void main(String[] args) {
System.out.print(factorial(5));
}
  public static int factorial(int x) {
int total = 0;

[Code] ....

But when I run this program it outputs 0 instead of 120. What is wrong with this code as it compiles just fine but doesn't work as intended.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved