• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 19:50
CEST 01:50
KST 08:50
  • 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 1 - Final Week4[ASL19] Finals Recap: Standing Tall10HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced6Weekly Cups (June 30 - July 6): Classic Doubles6[BSL20] Non-Korean Championship 4x BSL + 4x China10Flash Announces Hiatus From ASL70
StarCraft 2
General
The GOAT ranking of GOAT rankings RSL Revival patreon money discussion thread We need to be discussing a new patch right now! Firefly given lifetime ban by ESIC following match-fixing investigation RSL Season 1 - Final Week
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament $25,000 Streamerzone StarCraft Pro Series announced WardiTV Mondays
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
BW General Discussion A cwal.gg Extension - Easily keep track of anyone ASL20 Preliminary Maps BGH Auto Balance -> http://bghmmr.eu/ Script to open stream directly using middle click
Tourneys
Small VOD Thread 2.0 [Megathread] Daily Proleagues Last Minute Live-Report Thread Resource! [BSL20] Non-Korean Championship 4x BSL + 4x China
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile CCLP - Command & Conquer League Project Stormgate/Frost Giant Megathread The PlayStation 5 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 Russo-Ukrainian War Thread The Accidental Video Game Porn Archive Stop Killing Games - European Citizens Initiative
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 550 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
Calgary25980 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
The PiG Daily
22:50
Best Games of SC
Clem vs ByuN
SHIN vs GuMiho
PiGStarcraft419
LiquipediaDiscussion
SC Evo Complete
22:00
Enki Epic Ser. Taeja vs soO EN
davetesta58
Liquipedia
OSC
20:00
Mid Season Playoffs
Spirit vs GeraldLIVE!
Solar vs ShoWTimE
SteadfastSC209
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft419
SteadfastSC 209
Nina 158
JuggernautJason85
ViBE72
Nathanias 71
CosmosSc2 50
StarCraft: Brood War
NaDa 19
LuMiX 4
Dota 2
monkeys_forever346
canceldota150
NeuroSwarm85
League of Legends
Grubby3214
JimRising 334
febbydoto12
Counter-Strike
Fnx 2124
taco 772
sgares70
Super Smash Bros
hungrybox470
AZ_Axe123
Liquid`Ken48
Heroes of the Storm
Khaldor189
Other Games
summit1g10110
fl0m534
C9.Mang0146
Pyrionflax90
Trikslyr66
PPMD45
Livibee42
Organizations
Other Games
gamesdonequick43719
BasetradeTV21
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 47
• Adnapsc2 10
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Pr0nogo 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1520
Other Games
• Scarra1856
Upcoming Events
RSL Revival
10h 10m
SHIN vs Clem
Cure vs TBD
FEL
12h 10m
FEL
16h 10m
Gerald vs PAPI
Spirit vs ArT
CSO Cup
16h 10m
BSL20 Non-Korean Champi…
18h 10m
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
1d 10h
RSL Revival
1d 10h
Classic vs TBD
FEL
1d 15h
BSL20 Non-Korean Champi…
1d 18h
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Replay Cast
3 days
[ Show More ]
WardiTV European League
3 days
Replay Cast
5 days
The PondCast
5 days
Replay Cast
6 days
Epic.LAN
6 days
Liquipedia Results

Completed

KCM Race Survival 2025 Season 2
HSC XXVII
NC Random Cup

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.