• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:35
CEST 04:35
KST 11:35
  • 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
Maestros of the Game: Week 1/Play-in Preview4[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris34Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
Maestros of the Game: Week 1/Play-in Preview #1: Maru - Greatest Players of All Time Greatest Players of All Time: 2025 Update BoxeR's Wings Episode 2 - Fan Translation A Eulogy for the Six Pool
Tourneys
LiuLi Cup - August 2025 Tournaments $5,000 WardiTV Summer Championship 2025 Maestros of The Game—$20k event w/ live finals in Paris $5,100+ SEL Season 2 Championship (SC: Evo) Esports World Cup 2025
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
Easiest luckies way to get out of Asl groups BW General Discussion Post ASL20 Ro24 discussion. BGH Auto Balance -> http://bghmmr.eu/ No Rain in ASL20?
Tourneys
[ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! [ASL20] Ro24 Group E [ASL20] Ro24 Group D
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Mechabellum Path of Exile General RTS Discussion Thread Nintendo Switch Thread
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread The year 2050
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1232 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
Calgary25981 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
Code For Giants Cup
22:30
#25
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 136
NeuroSwarm 130
Nina 119
PiLiPiLi 7
StarCraft: Brood War
Britney 6194
Shuttle 772
NaDa 89
Larva 61
Icarus 11
Terrorterran 9
Dota 2
monkeys_forever199
LuMiX0
Counter-Strike
semphis_46
Super Smash Bros
C9.Mang0894
Other Games
tarik_tv16469
JimRising 460
WinterStarcraft356
ViBE81
Organizations
Other Games
gamesdonequick1778
BasetradeTV90
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH171
• davetesta56
• poizon28 10
• practicex 3
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki36
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
SC Evo League
9h 25m
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
Maestros of the Game
13h 25m
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[BSL 2025] Weekly
15h 25m
SC Evo League
1d 9h
Maestros of the Game
1d 13h
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
1d 16h
Team Bonyth vs Team Sziky
BSL Team Wars
1d 16h
Team Dewalt vs Team Sziky
Monday Night Weeklies
2 days
Replay Cast
2 days
Sparkling Tuna Cup
3 days
[ Show More ]
PiGosaur Monday
3 days
LiuLi Cup
4 days
Replay Cast
4 days
The PondCast
5 days
RSL Revival
5 days
Maru vs SHIN
MaNa vs MaxPax
RSL Revival
6 days
Reynor vs Astrea
Classic vs sOs
BSL Team Wars
6 days
Team Bonyth vs Team Dewalt
Liquipedia Results

Completed

Acropolis #4 - TS1
WardiTV Summer 2025
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 2
SEL Season 2 Championship
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
Maestros of the Game
EC S1
BLAST Rivals Fall 2025
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
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.