Language is Java and I have three integers ( t,r,s ). And on every one of them there will be a value.
algorithm chooses a smaller one of the values of variables t and r and places it in the variable s.
but how the algorithm does behave if int t and r have same value, both are for example 6?
integers
Started by jamesw, Nov 06 2008 05:54 AM
5 replies to this topic
#1
Posted 06 November 2008 - 05:54 AM
|
|
|
#2
Guest_Jordan_*
Posted 06 November 2008 - 06:14 AM
Guest_Jordan_*
I've moved this to the correct forum - Java. If both values are the same, for example 6, why would you not set variable "s" to 6?
#3
Posted 06 November 2008 - 09:01 AM
Since both have the same value, the result is the same whichever you choose.
#4
Posted 06 November 2008 - 10:48 PM
Thank you. Here it is, I made this. So; variable s will get a value 6. it really
gets a value 6, because "else s=r" - right.
2. and a little problem;
but is this sentence right; ((x % 3) == 0); ( * % IS BECAUSE mod, BUT IS == 0 RIGHT? *)
3.
and I want to say, that the int 10 has two numbers, 1 and 0. Is my solution right?
I think 10 is two letters and it is smaller than three letters 100. But maybe this is wrong.
gets a value 6, because "else s=r" - right.
public class static void main(String [] args) {
int t = 6, r = 6, s;
if (t<r) s=t;
else s=r;
2. and a little problem;
if x=8 ((x / 2) == 0);
but is this sentence right; ((x % 3) == 0); ( * % IS BECAUSE mod, BUT IS == 0 RIGHT? *)
3.
and I want to say, that the int 10 has two numbers, 1 and 0. Is my solution right?
I think 10 is two letters and it is smaller than three letters 100. But maybe this is wrong.
(((x > 10) && (x < 100)) || ((x < -10) && (x > -100)));
Edited by Jaan, 07 November 2008 - 02:26 AM.
Please use code tags when you're posting your codes!
#5
Posted 08 November 2008 - 07:59 PM
Yea, your solution to put the smallest of the two ints into 's' is correct although you may want to code a bit neater than that for readability.
2) I'm not quite sure what you asking here, however I'm going to take a crack at what I think you are looking for. x % 3 will never = 0 if x = 8, but x % 2 will, and you have the correct code for that...
3) Once again, not 100% sure what you are asking for, but I'm taking a crack at what I think you are looking for. For the most part, you are correct, however... (x >= 10) and (x <= -10) so that you include the number 10 in that, because 10 is two digits as well.
2) I'm not quite sure what you asking here, however I'm going to take a crack at what I think you are looking for. x % 3 will never = 0 if x = 8, but x % 2 will, and you have the correct code for that...
int x = 8; if ((x % 2) == 0) // do something
3) Once again, not 100% sure what you are asking for, but I'm taking a crack at what I think you are looking for. For the most part, you are correct, however... (x >= 10) and (x <= -10) so that you include the number 10 in that, because 10 is two digits as well.
#6
Posted 09 November 2008 - 01:34 AM
Thank you.
2.
I want to write how the claim would be output.? according to it
x / 3 would be;
((x % 3) != 0); ( * % IS BECAUSE mod, else it would be x / 3 )
I changed == TO != , because the result is not 0
Code:
if x=8
((x / 2) == 0);
3.
same thing here; I want to write how the claim would be output.
So the int 10 has two numbers, 1 and 0.
[B in the number 10 there are exactly two numbers;
[/B]
Code:
(((x > 10) && (x < 100)) || ((x < -10) && (x > -100)));
2.
I want to write how the claim would be output.? according to it
x / 3 would be;
((x % 3) != 0); ( * % IS BECAUSE mod, else it would be x / 3 )
I changed == TO != , because the result is not 0
Code:
if x=8
((x / 2) == 0);
3.
same thing here; I want to write how the claim would be output.
So the int 10 has two numbers, 1 and 0.
[B in the number 10 there are exactly two numbers;
[/B]
Code:
(((x > 10) && (x < 100)) || ((x < -10) && (x > -100)));


Sign In
Create Account


Back to top









