Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Question about shortcuts in java

https://puu.sh/rfPLU/805ef952b7.png
That is the code.
Its for one of my classes

Give three examples of shortcut arithmetic operators that are NOT used in the program above. Write the symbols for the operators and the names of the operations they are shortcuts for. (5 pts)

So my approach to this was

I didn't see them use the shortcuts of /= or *= but i don't see how it work in this since it was like val2 = num2 / val1;

maybe im not getting something. it seems really simple but idk..... sorry if its really dumb
Hmm. The only one I can see like you said is /=.
Code
num2 = num2/num1;
can be rewritten as
Code
num2 /= num1;


Unless the question was a general question, in which case only -= was used, and the three that weren't used were +=, =, and /=.
num1 = num1 + 5; <=> num1 += 5;
num1 = num1
5; <=> num1 *= 5;
num1 = num1 / 5; <=> num1 /= 5;

EDIT: There's also %= [num1 = num1 % 5; <=> num1 %= 5;]
That code is a damn eyesore, could you share it in plaintext?
I don't middleman any deals on- or off-site. Please don't message me requesting my past services and certainly don't fall for anybody who claims to be me.
(Sep 18, 2016 03:00 PM)minimalist Wrote:  That code is a damn eyesore, could you share it in plaintext?

int num1 = 4;
int num2;
double val1 = 4.0;
double val2 = 18;
num2 = 23;
int tnum = num2;
System.out.println("Printing values");
System.out.println("int num1 value = "+num1);
System.out.println("int num2 value = "+num2);
System.out.println("double val1 value = "+val1);
System.out.println("double val2 value = "+val2); System.out.println();

num2 = num2 / num1;
System.out.println( "orig num2/num1 "+tnum+"/"+num1+" = num2 = "+num2 );
num2 = 15;
System.out.println("resetting num2 value = "+num2); System.out.println();
val2 = num2 / val1;
System.out.println( "num2/val1 "+num2+"/"+val1+" = val2 = "+val2 );
num1 = 3;
val2 = num1 val1;
System.out.println( "num1/ val1 "+num1+"/"+val1+" = val2 = "+val2 );
num2++;
val1 -= num2;
System.out.println("after num2++: num2 value = "+num2);
System.out.println("after val1 -= num2: val1 value = "+val1); System.out.println();

System.out.println("val1 < num1 is "+( val1 < num1));
System.out.println( "val2 != num2 is "+(val2 != num2));


(Sep 18, 2016 02:55 PM)Probably Wrote:  Hmm. The only one I can see like you said is /=.
Code
num2 = num2/num1;
can be rewritten as
Code
num2 /= num1;


Unless the question was a general question, in which case only -= was used, and the three that weren't used were +=, *=, and /=.
num1 = num1 + 5; <=> num1 += 5;
num1 = num1
5; <=> num1 *= 5;
num1 = num1 / 5; <=> num1 /= 5;

EDIT: There's also %= [num1 = num1 % 5; <=> num1 %= 5;]
what does the %= do?
(Sep 18, 2016 03:03 PM)indeedm8 Wrote:  what does the %= do?

It's the modular, or remainder, function.

e.g. 7 % 5 = 2
7 / 5 = 1 + 2/5 <- it's the numerator in the remainder.
4 % 4 = 0
[Image: g1e3ykV.png]
  1. num2 /= num1;

  2. num2 += 1;

  3. System.out.println((val1 < num1) ? true : false);

  4. System.out.println((val2 != num2) ? true : false);



I don't fucking know, your teacher is not good at teaching lol.
I don't middleman any deals on- or off-site. Please don't message me requesting my past services and certainly don't fall for anybody who claims to be me.
Can declare the ints on the same line, Java is verbose enough don't make it more :P

int num2;

could just be
int num2 = num2 / num1;

Ect.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Tyler777Jul 10, 2019 03:10 PM 3 156 Jul 10, 2019 03:10 PM
Last Post: Stopbanningme
[Shell] by HackooFeb 8, 2017 10:54 AM 3 248 Feb 8, 2017 10:54 AM
Last Post: Nitr0Sage
[C#] by eXaByteSep 22, 2014 06:44 AM 12 164 Sep 22, 2014 06:44 AM
Last Post: eXaByte