![]() |
|
[Java] Question about shortcuts in java - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] Question about shortcuts in java (/showthread.php?tid=5409328) |
Question about shortcuts in java - indeedm8 - Sep 18, 2016 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 * - Probably - Sep 18, 2016 Hmm. The only one I can see like you said is /=. Code num2 = num2/num1;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;] * - minimalist - Sep 18, 2016 That code is a damn eyesore, could you share it in plaintext? * - indeedm8 - Sep 18, 2016 (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 /=.5; <=> num1 *= 5; num1 = num1 / 5; <=> num1 /= 5; EDIT: There's also %= [num1 = num1 % 5; <=> num1 %= 5;]what does the %= do? * - Probably - Sep 18, 2016 (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 * - minimalist - Sep 18, 2016 ![]()
I don't fucking know, your teacher is not good at teaching lol. * - Loses - Sep 18, 2016 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. |