• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:54
CET 19:54
KST 03:54
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies3ComeBackTV's documentary on Byun's Career !11Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win4Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2
StarCraft 2
General
ComeBackTV's documentary on Byun's Career ! Team TLMC #5: Winners Announced! What's the best tug of war? The Grack before Christmas Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies
Tourneys
OSC Season 13 World Championship $5,000+ WardiTV 2025 Championship $100 Prize Pool - Winter Warp Gate Masters Showdow Sparkling Tuna Cup - Weekly Open Tournament Winter Warp Gate Amateur Showdown #1
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 505 Rise From Ashes Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement
Brood War
General
BW General Discussion How soO Began His ProGaming Dreams Klaucher discontinued / in-game color settings BGH Auto Balance -> http://bghmmr.eu/ Recommended FPV games (post-KeSPA)
Tourneys
[BSL21] LB SemiFinals - Saturday 21:00 CET [BSL21] WB & LB Finals - Sunday 21:00 CET Small VOD Thread 2.0 [Megathread] Daily Proleagues
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Current Meta Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Mechabellum Stormgate/Frost Giant Megathread Beyond All Reason Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread 12 Days of Starcraft The Games Industry And ATVI Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced Where to ask questions and add stream?
Blogs
National Diversity: A Challe…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2145 users

Java help

Blogs > Live2Win
Post a Reply
1 2 Next All
Live2Win *
Profile Blog Joined July 2004
United States6657 Posts
Last Edited: 2008-02-02 05:28:37
February 02 2008 04:29 GMT
#1
After the following expressions are evaluated, what are the values of a, b, c, and d? Note that the expressions are all in one program and each expression might affect the next.

double a = 5, b = 2, c = 6, d;
------------------------------
a *= b;
------------------------------
c = a % 3 + c / b;
------------------------------
c = b– –;
------------------------------
a = _____
b = _____
c = _____
d = _____

-----------------------------------------------------------
I don't get what a *= means. I thought you needed a value to multiply a with?

And since I don't get the first one I can't get b, and since I can't get b I can't any of them -.-;;



Also,

Declare a variable alpha of type char and assign it an initial value of the lowercase letter g.

I think that means get alpha and set it to "g". But I don't think my code is right (it doesn't work when it's compiled either).

+ Show Spoiler [Please don't laugh] +
public static void main(String args[]) {
char alpha;
alpha = “g”;
}


***
SAY YES TO STIM KIDS!!! XD
Chill
Profile Blog Joined January 2005
Calgary25990 Posts
February 02 2008 04:35 GMT
#2
I think
X _= Y means X = X _ Y
So in your example: a = a*b
Moderator
Saracen
Profile Blog Joined December 2007
United States5139 Posts
February 02 2008 04:37 GMT
#3
yeah...
x+=5
is
x=x+5

so i guess what chill said
Saracen
Profile Blog Joined December 2007
United States5139 Posts
February 02 2008 04:40 GMT
#4
answers?
+ Show Spoiler +
a=10.0, b=2.0, c=1.0, d=0.0 ?
Daveed
Profile Blog Joined December 2006
United States236 Posts
February 02 2008 04:42 GMT
#5
If this is a Java question, why don't you open up eclipse or whatever you use, and try some of those expressions?
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
February 02 2008 04:45 GMT
#6
a = 10
b = 1
c = 2
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
Last Edited: 2008-02-02 04:53:01
February 02 2008 04:51 GMT
#7
you ask about multiplication but not modulo? strange

SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
Saracen
Profile Blog Joined December 2007
United States5139 Posts
February 02 2008 04:52 GMT
#8
On February 02 2008 13:51 fusionsdf wrote:
you ask about multiplication but not modulo? strange

modulus doesn't really matter in this question
Live2Win *
Profile Blog Joined July 2004
United States6657 Posts
February 02 2008 04:53 GMT
#9
On February 02 2008 13:51 fusionsdf wrote:
you ask about multiplication but not modulo? strange


I understand modulo :p

I actually looked this up and found out. Thanks for helping out guys.
SAY YES TO STIM KIDS!!! XD
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
February 02 2008 04:53 GMT
#10
yeah but I always found +=, -=,/=, *= intuitive.

modulo confused me quite a bit when I first saw it :O
SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
FreeZEternal
Profile Joined January 2003
Korea (South)3396 Posts
February 02 2008 05:03 GMT
#11
The line c = a % 3 + c / b; is useless here. -.-
Saracen
Profile Blog Joined December 2007
United States5139 Posts
February 02 2008 05:19 GMT
#12
On February 02 2008 14:03 FreeZEternal wrote:
The line c = a % 3 + c / b; is useless here. -.-

exactly
that's why b=2 and c=1
Live2Win *
Profile Blog Joined July 2004
United States6657 Posts
February 02 2008 05:25 GMT
#13
On February 02 2008 14:19 Saracen wrote:
Show nested quote +
On February 02 2008 14:03 FreeZEternal wrote:
The line c = a % 3 + c / b; is useless here. -.-

exactly
that's why b=2 and c=1

why? I don't get why it's useless.

a *= b;
a = a * b
a = 5 * 2
so,
a = 10

c = a % 3 + c / b
c = (10 % 3) + (6 / 2)
c = (1) + (3)
so,
c = 4

c = b--;
c = 2--
so,
c = 2
b = 1

Thus, a = 10, b = 1, c = 2

I'm not sure what "d" is. What's the default for that value?
SAY YES TO STIM KIDS!!! XD
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
Last Edited: 2008-02-02 05:34:01
February 02 2008 05:33 GMT
#14
On February 02 2008 14:25 Live2Win wrote:
Show nested quote +
On February 02 2008 14:19 Saracen wrote:
On February 02 2008 14:03 FreeZEternal wrote:
The line c = a % 3 + c / b; is useless here. -.-

exactly
that's why b=2 and c=1

why? I don't get why it's useless.

a *= b;
a = a * b
a = 5 * 2
so,
a = 10

c = a % 3 + c / b
c = (10 % 3) + (6 / 2)
c = (1) + (3)
so,
c = 4

c = b--;
c = 2--
so,
c = 2
b = 1

Thus, a = 10, b = 1, c = 2

I'm not sure what "d" is. What's the default for that value?


because you are setting c to some long equation

and then the very next step you set c to one less than b

In other words, you saved a value to c, didnt use it, and saved over it

as for d, it depends on the language. Java protects you, so it should be 0.0
SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
February 02 2008 05:38 GMT
#15
for:
public static void main(String args[]) {
char alpha;
alpha = “g”;
}

you have to use single quotes for chars (at least you do in C++ and I assume its the same here)

so it should be
public static void main(String args[]) {
char alpha;
alpha = 'g';
}

or you can combine the two steps to

public static void main(String args[]) {
char alpha = 'g';
}

which will initialize it with a value.


as a follow up to d, java protects you, but some languages don't. be careful relying on the value of a variable you didnt give a value to yet :O
SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
Macavenger
Profile Blog Joined January 2008
United States1132 Posts
February 02 2008 05:49 GMT
#16
For people saying the final variables are c=1 and b=2, look at it more carefully. b-- means evaluate b, then decrement b. At the start of that step b = 2, so c is set to 2, then b is decremented, giving c = 2 and b = 1. Most of you are doing c = b - 1; which is very different from c = b--;. For c to end up 1 using the -- operator, it would need to be c = --b; which would set both b and c to 1.
BottleAbuser
Profile Blog Joined December 2007
Korea (South)1888 Posts
Last Edited: 2008-02-02 07:32:06
February 02 2008 07:29 GMT
#17
+ Show Spoiler +
double a = 5, b = 2, c = 6, d;

a *= b; // equivalent to a = a * b, or a = 5 * 2, or a = 10

c = a % 3 + c / b; // equivalent to c = (10 mod 3) + (6 / 2), or c = (1) + (3), or c = 4

c = b– –; //equivalent to c = b; b = b - 1, or c = 2, b = 2 - 1, or c = 2; b = 1

End values:
a = 10
b = 1
c = 2
d is uninitialized.

Also, to set char alpha to lowercase g:

this will work:
char alpha = 'g';

this will also work:
char alpha; alpha = 'g';

this also will work:
char alpha; alpha = 71; // 71 is ASCII for 'g'
Compilers are like boyfriends, you miss a period and they go crazy on you.
BottleAbuser
Profile Blog Joined December 2007
Korea (South)1888 Posts
February 02 2008 07:54 GMT
#18
Um, what? You'll get a compile error if you try to access d, I think. d is uninitialized.

If d wasn't a primitive type, it would be equal to null. Since it is a primitive type, its value is uninitialized and you'd get a compile error.
Compilers are like boyfriends, you miss a period and they go crazy on you.
prOxi.swAMi
Profile Blog Joined November 2004
Australia3091 Posts
Last Edited: 2008-02-02 08:24:27
February 02 2008 08:08 GMT
#19
oh damn im way too late huh? T_T
anyway bottleabuser is right.
compiler would kick your face for trying to make use of d when there's no gaurantee that it won't be null. However, assuming d was initialized as 0, you'd get a = 10 b = 1 c = 2 d = 0
and the char one .. so ez.
char alpha = 'g';

is this for school?
Oh no
Cambium
Profile Blog Joined June 2004
United States16368 Posts
February 02 2008 08:15 GMT
#20
it's post decrement,

so c is 1 more than b.

and BottleAbuser is right. You can't compile your code unless you have d initialized.
When you want something, all the universe conspires in helping you to achieve it.
1 2 Next All
Please log in or register to reply.
Live Events Refresh
Next event in 1h 6m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko398
UpATreeSC 185
BRAT_OK 124
JuggernautJason53
MindelVK 43
Railgan 12
StarCraft: Brood War
Shuttle 766
Jaedong 693
Dewaltoss 158
firebathero 147
Larva 114
Rock 58
JulyZerg 45
Sexy 41
910 31
eros_byul 0
Dota 2
qojqva5285
canceldota55
Counter-Strike
fl0m602
Heroes of the Storm
Khaldor231
Liquid`Hasu147
Other Games
Grubby6825
Beastyqt687
B2W.Neo363
ToD246
DeMusliM214
ArmadaUGS172
XaKoH 114
Livibee55
Trikslyr36
Organizations
Other Games
gamesdonequick785
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• printf 45
• mYiSmile17
• Adnapsc2 6
• Dystopia_ 2
• Kozan
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV1114
• Ler67
• lizZardDota266
League of Legends
• Nemesis2796
Other Games
• imaqtpie1617
• Shiphtur280
Upcoming Events
BSL 21
1h 6m
Sziky vs eOnzErG
Sparkling Tuna Cup
15h 6m
Krystianer vs Classic
TriGGeR vs SKillous
Percival vs Ryung
ByuN vs Nicoract
OSC
23h 6m
BSL 21
1d 1h
Cross vs Dewalt
Replay Cast
1d 14h
Wardi Open
1d 17h
OSC
2 days
Solar vs MaxPax
ByuN vs Krystianer
Spirit vs TBD
OSC
5 days
Korean StarCraft League
6 days
OSC
6 days
[ Show More ]
OSC
6 days
Liquipedia Results

Completed

Escore Tournament S1 - W1
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL Season 21
CSL Season 19: Qualifier 2
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1 - W2
Escore Tournament S1 - W3
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
OSC Championship Season 13
Nations Cup 2026
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.