• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 20:16
CET 02:16
KST 10:16
  • 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 Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
[BSL21] Ro.16 Group Stage (C->B->A->D)0Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win0RSL Season 3: RO16 results & RO8 bracket13Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge2[TLMC] Fall/Winter 2025 Ladder Map Rotation14
StarCraft 2
General
Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win SC: Evo Complete - Ranked Ladder OPEN ALPHA Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge RSL Season 3: RO16 results & RO8 bracket RSL Season 3 - Playoffs Preview
Tourneys
RSL Revival: Season 3 $5,000+ WardiTV 2025 Championship StarCraft Evolution League (SC Evo Biweekly) Constellation Cup - Main Event - Stellar Fest 2025 RSL Offline Finals Dates + Ticket Sales!
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death
Brood War
General
[BSL21] Ro.16 Group Stage (C->B->A->D) Data analysis on 70 million replays soO on: FanTaSy's Potential Return to StarCraft 2v2 maps which are SC2 style with teams together? What happened to TvZ on Retro?
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Tie Breaker - Group B - Sun 21:00 CET [BSL21] RO16 Tie Breaker - Group A - Sat 21:00 CET Small VOD Thread 2.0
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Clair Obscur - Expedition 33 Should offensive tower rushing be viable in RTS games? 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
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread The Games Industry And ATVI Things Aren’t Peaceful in Palestine About SC2SEA.COM
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
The Health Impact of Joining…
TrAiDoS
Dyadica Evangelium — Chapt…
Hildegard
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2004 users

Java help

Blogs > Live2Win
Post a Reply
Normal
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
Calgary25989 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.
BottleAbuser
Profile Blog Joined December 2007
Korea (South)1888 Posts
February 02 2008 08:20 GMT
#21
I GOT IT!

It's a fucking trick question! The code won't compile, so a, b, c, and d won't have any value at all! AHAHAHAHAHAHAH. OK, the teacher probably won't accept that answer, so go with what I put in my first post.
Compilers are like boyfriends, you miss a period and they go crazy on you.
Live2Win *
Profile Blog Joined July 2004
United States6657 Posts
February 02 2008 08:54 GMT
#22
lol thanks guys.

I already submitted with d=0. I probably should have put "uninitialized" though, that seems like a better answer.

Thanks for your help though.

Yea, it's for my CIS3022 class
SAY YES TO STIM KIDS!!! XD
Normal
Please log in or register to reply.
Live Events Refresh
OSC
23:00
OSC Elite Rising Star #17
CranKy Ducklings151
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JuggernautJason136
Nathanias 113
Vindicta 10
StarCraft: Brood War
Britney 15421
Calm 2471
Artosis 609
NaDa 47
ggaemo 12
Dota 2
NeuroSwarm34
League of Legends
Cuddl3bear4
Super Smash Bros
hungrybox1056
C9.Mang0249
PPMD76
Other Games
summit1g9428
Grubby2922
Maynarde122
Trikslyr65
PiLiPiLi5
fpsfer 3
Organizations
Other Games
gamesdonequick912
Dota 2
PGL Dota 2 - Main Stream351
Other Games
BasetradeTV31
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• RyuSc2 40
• davetesta40
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• Azhi_Dahaki13
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota22605
League of Legends
• Doublelift4865
Other Games
• imaqtpie1068
• Shiphtur224
Upcoming Events
Wardi Open
10h 44m
PiGosaur Cup
23h 44m
Replay Cast
1d 7h
Wardi Open
1d 10h
OSC
1d 11h
Tenacious Turtle Tussle
1d 22h
The PondCast
2 days
Replay Cast
2 days
OSC
3 days
LAN Event
3 days
[ Show More ]
Replay Cast
3 days
Replay Cast
4 days
Sparkling Tuna Cup
5 days
Replay Cast
5 days
Wardi Open
6 days
Replay Cast
6 days
Liquipedia Results

Completed

SOOP Univ League 2025
RSL Revival: Season 3
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
META Madness #9
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
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.