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


ADVERTISEMENT

Handling Large Numbers

Oct 31, 2014

I found an exercise online to create a small program . I have this code that I have done so far:

import java.util.Scanner;
public class Test {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long a = sc.nextLong(); long b = sc.nextLong();
long count = 0; // counter

[code]....

The program should read the numbers a and b and list how many numbers between a and b are divisible by either 2, 3 or 5. If the user types the number 5 and then 8.... it would look at all the numbers in between - 5,6,7,8 and check if any of them are divasable by either 2,3 or 5. And since the numbers 5,6,8 are it would return the number 3 to the user..Now the problem is that this program only works for small numbers, but when I try to input numbers such as 123456789012345678 and 876543210987654321... it doesn't run at all.

So there needs to be a quicker way on how the program checks the numbers divisibility instead of checking each one. Here is where I am lost. How to fix the program that it will read bigger numbers such as a=123456789012345678 b=87654321098765432..There must be a quicker way ...something that can modify the code so it finishes in the matter of seconds not hours. Something that will fasten the process of checking if the numbers are dividable.

View Replies View Related

Is Handling Instance Of Error Or Its Subclass Is Also Called Exception Handling

Mar 7, 2014

I have studied about the hierarchy of exception classes in which Throwable class comes at the top and two of its direct subclasses are Error and Exception..I just want to ask if in some code snippet we throw an instance of Error or its subclass within the try catch block then will that be also called "exception handling" ? I am asking this because Error class is not a child class of Exception therefore cant be said an Exception, therefore handling the same should not be called exception handling

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

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 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

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

File Handling In A GUI

Apr 28, 2014

I created a GUI using Java with Buttons, Pictures and labels.When one of the buttons is pressed it increases the price, which can be seen by the labels increasing the necessary amount.What I would like to be able to do in my GUI is allow the user to record details of the sale and be able to display the sales of past customers to date, by this I mean when I click one of the buttons it will record the amount of that item into a file and when I press the another button, not the same button as the items, it will show the user the existing orders that have been taken in the past.

Here is my Code:

//Importing needed classes
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
 
[code]....

View Replies View Related

Handling IO Synchronization

Sep 16, 2014

I have a class (WriteExcel) which writes to an excel file. For those who don't know, Excel doesn't handle multiple access well (or at all).

I then have another class (WriteManager) which creates a new thread for each write command, and then calls a method from the WriteExcel class.

Other classes in my project calls methods from WriteManager to send their requests. My situation looks like this:

1) Thread 1: Someclass -> WriteManager.write1stPage(write) -> Creates Thread 2 -> WriteExcel.write1stPage(write) -> Start Excel Write
2) Thread 1: Someclass -> WriteManager.write2ndPage(write) -> Creates Thread 3 -> WriteExcel.write2ndPage(write) -> Start Excel Write
3) Thread 1: Someclass -> WriteManager.write3rdPage(write) -> Creates Thread 4 -> WriteExcel.write3rdPage(write) -> Start Excel Write
4) Thread 2: Finished writing and ready to save -> Throws exception due to multiple Excel access
5) Thread 3: Finished writing and ready to save -> Throws exception due to multiple Excel access
6) Thread 4: Finished writing and ready to save -> Throws exception due to multiple Excel access

I need to figure out a way to restrict access to WriteExcel until the writing is finished. So I need something like this:

1) Thread 1: Someclass -> WriteManager.write1stPage(write) -> Creates Thread 2 -> WriteExcel.write1stPage(write) -> Start Excel Write
2) Thread 1: Someclass -> WriteManager.write2ndPage(write) -> Creates Thread 3 -> Waits Until WriteExcel is free
3) Thread 1: Someclass -> WriteManager.write3rdPage(write) -> Creates Thread 4 -> Waits Until WriteExcel is free
4) Thread 2: Finished writing and ready to save -> Saves and frees WriteExcel
5) Thread 3: WriteExcel is free -> WriteExcel.write2ndPage(write) -> Start Excel Write
6) Thread 3: Finished writing and ready to save -> Saves and frees WriteExcel
7) Thread 4: WriteExcel is free -> WriteExcel.write3rdPage(write) -> Start Excel Write
8) Thread 4: Finished writing and ready to save -> Saves and frees WriteExcel

What is currently the best approach in java for handling this sort of situation?

View Replies View Related

Packages And Exception Handling?

Aug 17, 2014

Is there any connection between packages and exception handling in java. Means is it necessary to create a package before trying exception handling examples?

View Replies View Related

Exception Handling In A Constructer

Apr 22, 2014

Is there a special mechanism through which exception can be handled in a constructor?

Suppose while creation of an object there occurred an exception while creating an object, and the object is half constructed. How do we make sure we handle this kind of exceptions in a constructor?

View Replies View Related

Handling Sprite Overlapping?

Sep 16, 2014

The game I am working on now is an overhead game. Anyways I have a visual issues with the sprites where they overlap. I mean its normal to have sprites overlap but I do not want one to appear like it is walking on top of the other rather than the ground. The below is an image illustration the issue I want to address. (I am really good at drawing)

On the right you see what I want my sprites to do, but on left you see overlap in the way I am trying to avoid.

Now my approach to this problem is taking my array of monsters (a class that extends JLabels) and reordering them based on which monster is higher I make this occur at every run of my thread. It seems to me that if a monster is higher it should be added to the screen before the one that is lower. So I try to keep resorting the array of monsters at every iteration of my main game loop based on who is higher to account for the overlap

if (e.getSource() == follower){
c =0;
for (monster m: monsters) {
//Arrays.sort(monsters, new whoHigherComparator()); //I tried having the sort happen here
m.movingToPlayer(joe);//1
Arrays.sort(monsters, new whoHigherComparator());//2
layeredScene1.add(m, new Integer(3));//3

[code]...

The above is code that shows the majority of my games flow I will describe my flow with references to the commented lines above with [num] for better understanding of where I am coming from. Basically, there is a set number of monsters, the monster all locate and move to the player [1], then I attempt to sort the monster array based on height [2], then add my re-sorted monsters back onto the pane in order [3], then bumpers (a type that handle collision and make sure monsters don't overlap too much) attach the current monster [4], if bumpers are touching monsters arae moved away from each other until their bumpers are no longer touching [5], if the monster is moving leftwards set the animation to a leftwards walk [6], and likewise for rightwards walking [7]

By the way this is my comparator

public class whoHigherComparator implements Comparator<monster>
{
@Override
public int compare(monster m1, monster m2) {
System.out.println("comping?");
int h1 = m1.getY();
int h2 = m2.getY();
if (h1 < h2)

[code]...

At this point everything in my game flow works just fine, its just the annoying "walking on top of each other" effect that I am having trouble handling. And my attempt at this is line [2] & [3] from my game flow which seems like it would be an effective way to handle the "walking on top of another" effect but its surely not working. I also swapped the returns from my comparator but still no changes. It seems that maybe the array isn't being sorted and/or these changes are just not being reflected.

View Replies View Related

Exception Handling For Strings?

Nov 25, 2014

For one of my last labs for the semester, my professor is having the class go back to our very first program and apply some of the exception handling that we just recently learned about. Here's my improved code so far:

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

[code]....

My code compiles fine, but even if I enter an integer or a double, it saves the number as a string, and prints that out as the name. Is there any way to get around this? Or do I need to use something besides a try-catch?

View Replies View Related

JSF :: Error Handling Via Servlet

Feb 19, 2014

On click of the ok button from a JSF page, a servlet is called on a new window. Servlet creates a CSV file , which will be streamed back for a download. Now if there is a error in the servlet, how can this be shown in the parent JSF?

View Replies View Related

Exception Handling And Text I/0

Apr 19, 2015

I have been working on a problem dealing with exception handling and text input output for a few days now. The exercise is a two part exercise. The first part of the exercise I have to write a program to display the total salary for assistant professors, associate professors, full professors, and all faculty, respectively, and display the average salary for assistant professors, associate professors, full professors, and all faculty, respectfully using the what is posted on the [URL] .... Each line in the file consists of a faculty member's first name, last name, rank, and salary. The second part of the exercise I have to take my code and change it so that it

-lets the user enter the name of the file to be read,
-Uses a try-catch block to handle the FileNotFoundException displaying instead The file already exists..
... Use a second catch block to ignore any other exception thrown.
... Design your code so that, if the user enters a file that does not exist, the program prompts the user to enter again a file name.

and I need to Note: In order to catch the FileNotFoundException, you need to include import

java.io.FileNotFoundException;

package pkg14.pkg25;
import java.util.Scanner;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

[code]...

View Replies View Related

Handling MVC Design With DatabaseDAO

Mar 31, 2015

I have done this a few times but I want to make sure I am doing it correctly. In other words creating a clean understandable program. Instead of posting code I will just talk about this is my plan:

Create a model (getter and setters)
Create a view (via swing)
Create a controller (pass the model and view in the parameter)

Database DatabaseConnection:
Use the singleton pattern

Database:
Create an interface called Database with all the queries I will need (insert, delete etc)
Create a class called DataBaseDAO and implement the interface database and get an instance of the DatabaseConnection.

Tying it all together:

In the controller should I use the "new" operator and create a new database class or extend the database class? I am thinking I should not do it in the controllers constructor but make a field if I use the "new" operator like:

private Database db = new Database();
Create a class called App
Create a new Model
Create a new View
Pass the view and model into the controllers parameter.

Am I on the right track? Is this messy? Is there a better way of doing it?

View Replies View Related

Java File Handling

Aug 20, 2014

Assume we have 2 files that are input.txt and output.txt Input.txt has Name||Age||email||contact No||Name1||age1||email1||contact No1||name2||Age2||email2||contact no2||etc...

initially the output.txt does not have any record.using a java program we have to make it as

Names in the input file:Name,Name1,Name2,Name3 Ages in the input file:Age,Age1,Age2,Age3 email id in the file: email, email1, email2 Contact no in the file:contact no, contact no1,contact no2

View Replies View Related

Error Handling / Validation In GUI

Feb 10, 2014

I have a GUI that prompts the user for information. When they click 'submit', a new customer gets created from a class like so ...

Java Code:

public void actionPerformed(ActionEvent arg0) {
Customer customer = new Customer(); // New customer object
customer.name = view.getName();
customer.age = Integer.parseInt(view.getAge());
customer.ccn = view.getCCNumber(); mh_sh_highlight_all('java');
I am having difficulties validating my variables for nulls. For instance ...

Java Code:

// METHOD TO RETRIEVE TEXTBOX INPUT -- NAME
public String getName() {
String name = null;
if (jtfFirstName.getText() == null || jtfLastName.getText() == null || !jtfFirstName.getText().matches("[a-zA-Z]+") || jtfLastName.getText().matches("[a-zA-Z]+")){ // Validate name fields
JOptionPane.showMessageDialog(null, "<html><i>Improper Input Detected.</i>

[code]...

I can't seem to win with this. Whether the fields are filled in properly or not, I get the error message and the program continues to completion using the name "null".

View Replies View Related

Migration Of Large Application From JDK 1.4 To 1.6

Nov 6, 2014

I want to migrate some large application code base's from jdk1.4 to jdk1.6.
 
1. Is there any tool/s available that can be used for this migration (Because manually it is very difficult for a application with almost 15,000 java files and 15 * 10^6 KLOC within a limited time frame).

2. Steps that should be followed in such cases.

3, If any tool is not available for such activity what are the salient points that are needed to be considered while migrating.

View Replies View Related

SwingGUI - Display Large Information Set

Aug 16, 2014

I have a simple display method in a java project as given below:

public void displayInfo() {
for(Student student : studentdB){
System.out.println(student.toString() + "
");
}

I would want to use one of Swing components to display the students instead of displaying them on the stdout. How I could go about calling this method in some Swing components that can display all the students in the studentdb?

View Replies View Related

How To Use RSA For Encryption / Decryption Of Large Files

Mar 14, 2015

I need to encrypt/decrypt file contents using RSA . But the default nature of RSA I could not upload files larger than 177 bytes for key length 1024 bytes . How it can avoid , I look it for a 100 times yet...

I attach my encryption files here ...

See attached files for more details ...

View Replies View Related

Writing A Large Symbol In The Console

Sep 3, 2014

What I'm tasked to do, is to make a simple Java class that forms a "V" based on whatever height the user would desire, made out of stars "*", and spaces " ".

For example, if a user desires a "V" with a height of 3, it would look print out something like;

* *
* *
*

Where a "V" with a height of 5 would look something like:

* *
* *
* *
* *
*

(That one didn't look too good, but you get the point, it's suppose to be 5 "high" and shaped like a "V"). The problem I have, is that I don't see what loops within loops within loops I would need to build something like this.

All the easy stuff like asking the user what height they want and such, I can handle, but I don't see how this thing is suppose to be coded, to print out a decent-looking and right-sized "V" in the console.

public static void main(String[] args) {
int height = 3;
for (int i = 0; i < height; i++) {
for (int j = 0; j < 2/(height+1)+1; j++) {
if(j == i) {

[Code] ....

Looked like something of a good start, and it drew me half (!) of the "V" in the size I wanted. Am I on to it here, or am I on the moon in terms of progress? I need the entire "V", not just a nice "".

View Replies View Related

Achieving Performance On Large Data?

Oct 10, 2013

I have an application which has 10 million rows and 1000 columns in Oracle. Each value has a different set of calculations that are stored in User Defined PLSQL functions.

Data is displayed in form of data grid. When a user updates any value, the calculation is performed using plsql function and value is stored in database. Is there an easy way through which calculation is performed on the fly and i get maximum performance ?

View Replies View Related







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