How To Find If BigInteger Is Square

Jul 3, 2014

I have a program i m not sure how to implement :

(Square numbers) Find the first ten square numbers that are greater than Long.MAX_VALUE . A square number is a number in the form of n 2 . For example, 4, 9, and 16 are square numbers. Find an efficient approach to run your program fast.

I found two ways of solving this but i think both are way inefficient :

-A square number can be divided in lesser square numbers :

what's the square of 36 ? 36 is 2 * 3 * 2 * 3 => 4 * 9 => square is 2 * 3

-second option is to estimate a number and increase it or decrease it based on how close that number * number is to the BigInteger starting number , as as it gets closer the delta gets smaller until it gets to 1

View Replies


ADVERTISEMENT

Find Area Of Triangle / Square / Rectangle Or Trapezoid

May 19, 2014

I started with finding the area of a triangle, but now I'm trying to ask a user what kind of shape they want the area for, then ask questions to get the area. I can't figure out how to take the shape a person types to go to a certain case. It also says shape hasn't been initialized. I don't know how to do that.

import java.util.Scanner;
public class TriangleArea {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args){
char shape;
String text = "Do you want to find the area of a triangle, square, rectangle, or trapezoid?";
System.out.print("Text");
switch(shape){

[code]....

View Replies View Related

Algebra - Perfect Square Java Program / Find Smaller Integer N

Sep 22, 2014

Write a program that prompts the user to enter an integer m and find the smallest integer n such that m * n is a perfect square. (Hint: Store all smallest factors of m into an array list. n is the product of the factors that appear an odd number of times in the array list. For example, consider m = 90, store the factors 2, 3, 3, 5 in an array list. 2 and 5 appear an odd number of time in the array list. So, n is 10.)

so far my program is just like this.

import java.lang.Math;
import java.util.Scanner;
public class PerfectSquare {
public static void main(String[] args) {
Scanner m = new Scanner(System.in);
int Fint;

[Code] .....

how do i make the program find the smallest integer n?

View Replies View Related

Creating Cursor For A Game That Moves Square By Square - Removing Trailing Images

Aug 31, 2014

I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.

As a visual explanation, this is what the program looks like on launch:

This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):

And this is what it actually looks like after you press the right arrow key once:

Here is the code for the program:

package cursortest;
import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
public class CursorTest extends JPanel implements KeyListener{

[Code] ......

I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.

View Replies View Related

How To Compare Square Of The Square Root Of Any Number

Feb 20, 2014

How would I compare the square of the square root of any number. The difference in these values is due to the rounding error in Java.

Example: Enter number 2

The answer I should get is: 2.000000000000004
Round off error: -4.440892

View Replies View Related

Int To BigInteger Conversion?

Oct 13, 2005

How to convert an 'int' to BigInteger.

View Replies View Related

While Loop With BigInteger

Sep 4, 2014

i want to make an while loop that uses a bigInteger. but it want do it, so what do i do?

View Replies View Related

Storing Biginteger In Array?

Apr 1, 2014

how can i store biginteger in an array?

View Replies View Related

Permutation Of 5 Digit Number With BigInteger

Jan 23, 2014

i have tried permutation with big Integer in Java. it works fine upto 4 integer input say 3456 P 2345 but nothing happens in console when i type 5 digit input..here is my code

public class cvic {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter n and r: ");
BigInteger n = scan.nextBigInteger();
BigInteger r = scan.nextBigInteger();
System.out.println("nPr = "+fact(n).divide(fact(n.subtract(r))));

[code]....

View Replies View Related

Handling Very Large Numbers Without Using BigInteger?

Dec 9, 2014

I am calculating an exponent without using BigInteger. However, I find that using long is not enough to handle my code. Is there a way to handle large numbers without using BigInteger?

public static void main (String[] args){
int base = 3;
int exponent;
long total = 1L;
boolean n;
Scanner input = new Scanner(System.in);

[code].....

View Replies View Related

Eclipse - Sorting BigInteger Arrays

Mar 23, 2014

I am currently working on Project which involves me needing a BigInteger array and sorting it somehow. I have been able to do

* Array.sort(arrayname); *

In past codes, but Eclipse is telling me that I can't do this with my BigInteger array. I have already imported java.util.Arrays

View Replies View Related

How To Input BigInteger Parameter Values Using JConsole

Jan 9, 2015

I am trying to test my JMX bean in JConsole.  How do I input BigInteger parameter values using JConsole? It appears to want a numeric value, but everything I have tried results in an IllegalArgumentException saying there is a ClassCastException.

View Replies View Related

Magic Square Says No

Nov 25, 2014

I'm having a small issue with my output on my code. here is what my output is: The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.

Please enter the 4 values for row 0, separated by spaces: 1 2 15 16
Please enter the 4 values for row 1, separated by spaces: 13 14 3 4
Please enter the 4 values for row 2, separated by spaces: 12 7 10 5
Please enter the 4 values for row 3, separated by spaces: 8 11 6 9
Checking square for problems:
DIAG: VALID
ROWS: VALID
COLS: VALID
RANG: VALID
MAGIC: No

MAGIC should be YES. However i keep getting it saying no.This is the correct output..The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.

Please enter the 4 values for row 0, separated by spaces: 1 2 15 16
Please enter the 4 values for row 1, separated by spaces: 13 14 3 4
Please enter the 4 values for row 2, separated by spaces: 12 7 10 5
Please enter the 4 values for row 3, separated by spaces: 8 11 6 9

Checking square for problems:
DIAG: VALID
ROWS: VALID
COLS: VALID
RANG: VALID
MAGIC: YES

Here is my code..

import java.util.Scanner;
public class pdonahue_Magic {
public static void main(String args[]) {
int[][] theSquare = new int[4][4];
Scanner s = new Scanner(System.in);
System.out.println.

("The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.");

System.out.print("Please enter the 4 values for row 0, separated by spaces: ");
theSquare[0][0] = s.nextInt();
theSquare[1][0] = s.nextInt();
theSquare[2][0] = s.nextInt();
theSquare[3][0] = s.nextInt();

[code]....

View Replies View Related

How To Make Square Which Is Filled With (dot)

Oct 17, 2014

Do I want to make something like this:

*****
*.....*
*.....*
*.....*
*****

I am stuck, I have made a code that creates this and don't know how to complete it.

*****
* *
* *
* *
*****

Code:

class Main {
public static void main( String args[] ) {
System.out.print("#Enter number of stars :");
int stars = BIO.getInt();

[Code] ....

View Replies View Related

Nth Square Root Of Any Number

May 14, 2009

This is a mathematical problem. I got one of the equations I need to compute down to

n^(1/6)

Or the 6th root of n.

Now the Java code I have for this is as follows, since Java has no nth root function I'm raising it to a power of a 1/6.

System.out.println(Math.pow(64.0, 1/6));

Now, the only thing it will print is 1.0

However the 6th root of 64 is 2!!!!

View Replies View Related

Create Square Matrix That Has Min And Max Value

May 10, 2015

I have to create a square matrix that has a min and max value as well as a size value which is given a integer value in the main method. The matrix has to be filled with random values. Also I have to add that matrix to another one in an addMatrix method and I have to subtract both in a subMatrix method. These are the requirements:

Methods:
Constructor() - receives the row and col size for myMatrix and a max and min values for range of random fill values for the matrix.
RandFill() - fills matrices with random numbers
addMatrix() - receives a matrix object. adds its myMatrix with the received object's myMatrix. The result is placed in this object's myResultMatrix.
subMatrix() - subtracts both matrices

I typed up this code but I'm not sure about some parts of it and I would creating min and max values in the Random method and in the main printing the separate 2 matrices and adding and subtracting them:

import java.util.*;
public class SquareMatrix2 {
public int size;
public int myMatrix [][];
public int myResultMatrix;
public int [][] ResultStatus;

[Code] ....

View Replies View Related

Timer - Why Does Square Not Moving

Sep 7, 2014

Why does my program write that i have problem in Timer?

public class Ball extends JPanel implements ActionListener {
Timer timer = new Timer (3, this);
int x = 0, y = 0, aX = 2, aY = 2;
public void PaintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;

[Code] ....

View Replies View Related

Creating Solid Square

May 3, 2014

I aim to create a solid square using this:

public class asteriskSquare {
public static void main(String[] args) {
for (int x = 1; x <= 4; x++){
for (int y = 1; y <= 4; y++){
System.out.println("+");
}
System.out.println("+");
}
}
}

All I'm getting is a single column of "+".

View Replies View Related

Multidimensional Array With Size Only In The First Square

Jan 14, 2014

I come to the point: I just started to learn java through various manuals and in one of them I came across a declaration of an array that I do not understand:

int[][] multiArr = new int[2][];

the manual says that you can allocate the multidimensional array multiArr by defining size in only the first square bracket but I can't undestand how you can use this array. Seems to be no way to store data with it!

View Replies View Related

Magic Square Won't Pass The Tests

Feb 11, 2015

public class MagicSquare {
public boolean isSquare(int[][] arr) {
if(arr.length == arr[0].length)
return true;
else
return false;

[Code] ....

View Replies View Related

Diamond In A Square Grid Of Dots

Nov 14, 2014

I am new to java and i am trying to make a Java application which prints a diamond in a square grid of dots whose side length is input to the application.When you run the code is should be like this:

..*..
.*.*.
*...*
.*.*.
..*..

My java code print this:

..*..
.***.
*****
.***.
..*..

Here is my code:

class Main {
public static void main(String args[]) {
System.out.println("#Enter size of Diamond :");
int longestRow = BIO.getInt();
for(int row=1 ; row<=longestRow ; ++row)

[Code] .....

View Replies View Related

Draw Square With Asterisks (for Loops)

Apr 21, 2015

So currently I'm trying to learn how to draw a square with asterisks based on the input I give for it's sideLength.

So if I have a Square(5) it should draw a 5x5 looking like this:

*****
*****
*****
*****
*****

but then in the main method, it should draw multiple squares of given sizes, so say 5, 6, and 7. Making a square for each of the given numbers. This is what I currently have so far ....

class Square {
int sideLength; Square( int size ) {
sideLength= size;
} int getArea() {
return sideLength * sideLength;

[Code] ....

View Replies View Related

Why Program Not Printing Square And Triangle

Nov 21, 2014

import java.util.Scanner;
public class justin10a

public static void main(String [] args)
{
int n;
n = getSize();
 
[Code] .....

View Replies View Related

Utility Functions For Square Matrices And Arrays

Nov 7, 2014

I am working on a number of utility functions for square matrices and arrays, and I keep having trouble with segmentation faults.

arrayUtils~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class ArrayUtils {
//This function takes an array a, and returns the sum between indices
//i and j, where i is the lower index and j is the upper index. int size makes
//sure that the function doesn't go out of bounds.
public static int subSum(int[] a,int i, int j) {
int sum=0;

[Code] .....

View Replies View Related

Creating A Matrix For Magic Square Project

Jan 12, 2015

I am making a program that reads a set of numbers (e.g.: 8 1 6 3 5 7 9 4 2) and prints them into a matrix.For example:

8 1 6 3 5 7 9 4 2, will produce:
8 1 6
3 5 7
9 4 2

When taking in these numbers from the user, I am not allowed to let the user state what size the matrix is (e.g.;3 x 3). Instead the program needs to determine that itself. I have written the code below to count the number of numbers inputted, but now I am stuck as to how to get them into the array. I have what is suppose to be my array written, but it is not function yet.

import java.util.*;
public class MagicSquare {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

Word Counter - Show Number In Square Box

Jan 3, 2015

My code compiles and runs just fine, i'd just like to get creating a small square box that shows number of words used next to the "word count = ". i'd wanto to press the count words button to count and show the number in the square box. here is my code.

import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class wordCount extends JFrame implements ActionListener

[Code] .....

View Replies View Related







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