Java Queries Here..

OP
furious_gamer

furious_gamer

Excessive happiness
@prateek007391

Finally you got it work...:D

BTW I prefer Eclipse over NetBeans. NB Simply reduces all of your work of structuring a project folder and similar works. Use Eclipse 3.5 Galileo or Ganymade.
 

Jaskanwar Singh

Aspiring Novelist
help on programs in netbeans please -
how to make a program that tells whether a number is prime or not.
and how to print fabonacci series (0112358..)
 
OP
furious_gamer

furious_gamer

Excessive happiness
help on programs in netbeans please -
how to make a program that tells whether a number is prime or not.
and how to print fabonacci series (0112358..)

Is it you school assignment, anyhow it's very basic program

The logic is :

First get till what limit you want the series to be continued.
1. Add first two number.
2. Put it in a variable.
3. Iterate till u reach the given limit.
4. Each time when u iterate add the numbers.
5. Inside the loop swap ur numbers.

For Prime Number :

A prime number is a whole number that is divisible only by one and itself. 3 can is divisible by 1 and 3, and is prime. 6 is divisible by 1, 2, 3, and 6, and is not prime. 1 is not counted as prime, making 2 the first prime number, and the only even prime number.

So, if you understand this logic, it is easy to do the code.
 

Liverpool_fan

Sami Hyypiä, LFC legend
I'll recommend you to use the recursive algorithm for fibonacci series. Iterative algorithm isn't quite natural enough to code.

0, 1, 1, 2, 3, 5, 8 is patter like f(n) = f(n-1) + f(n-2), so just recursively call f(n-1) and f(n-2), and terminate by returning 1 when you get 1 as input.

And for prime numbers, use boolean flags for flagging whether the number the prime or not.
 
actually liverpool fan i am just a beginner. :-D. dont know recursive algorithm.

that is not a problem. there r tons of tutorials on the net.

here is the one which i used. bit lengthy but sure it covers every possiblity from analysis to designing algo.

gave GATE yesterday and it had 2 2-marks ques on recursion. so recursion can become confusing if taught incorrectly. better if u r prepared.
 

sanithkk81

Broken In
I want to use multi page editor in my java eclipse plug in project. I'm having a wizard. I want to navigate to the multi page editor the moment I press "Finish" button. I've finished the gui design of both editor and wizard. But when I run the program after displaying the product splash screen it shows launch error and terminates the application. In error log it shows product file and editors bundle are not present. Help me out to remove the error
 
Last edited:

RBX

In the zone
What is the difference in 'i = i + x' and 'i += x' ?

Code:
int i = 1;
i = i + 1.2;

produces compile time error (possible loss of precision), while
Code:
int i = 1;
i += 1.2;
doesn't.

I think it has something to do with type promotion but I couldn't understand when exactly would it be applied.
 

QSilver

Right off the assembly line
Create a class Book having field bookno , title , status(whether available or not) , author , last issue date and price.Create constructor and method to create an instance of a book.Create method issue(),received() ,is available() %get issue date().

Test the application with objects
 
What is the difference in 'i = i + x' and 'i += x' ?

Code:
int i = 1;
i = i + 1.2;

produces compile time error (possible loss of precision), while
Code:
int i = 1;
i += 1.2;
doesn't.

I think it has something to do with type promotion but I couldn't understand when exactly would it be applied.

implicit calculation is int type. compilation error is due to mismatch type. the proper casting could be :
Code:
int i = 1;
i = i + (int)1.2;
or
Code:
int i = 1;
 i = (int)((float)i + 1.2);

in your second code 1.2 is implicitly coverted to int i.e the value is 1

hoping u get the concept :smile:
 

RBX

In the zone
^^ I'm beginner at Java but my concepts say that Java has only safe implicit conversion that avoid truncations but i += double return int for some reason.

Only implicit conversion known to me is String + something = String.

---------- Post added at 10:26 PM ---------- Previous post was at 08:17 PM ----------

A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.

from: Expressions
 
^^ I'm beginner at Java but my concepts say that Java has only safe implicit conversion that avoid truncations but i += double return int for some reason.

Only implicit conversion known to me is String + something = String.

---------- Post added at 10:26 PM ---------- Previous post was at 08:17 PM ----------

A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.

from: Expressions

JavaDocs r never wrong. i like them more than MSDN.

your compilation error occurs not due to compound statement but operation on different datatypes, one int and other float.

u cannot place float value in int, without truncation.

and String + something = String is not implicit conversion, i repeat, not implicit conversion, + operator is overloaded in case of String for concatenation.
Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

safe implicit conversion does not mean that datatypes of binary operands can be different
see: Expressions
 

Garbage

God of Mistakes...
and String + something = String is not implicit conversion, i repeat, not implicit conversion, + operator is overloaded in case of String for concatenation.
Can you please elaborate on this? I think I didn't get you. What do you mean by not implicit?

By implicit I understand JDK/JRE automatically converts it, you don't have to do it manually (invoking any method).
 
Top Bottom