Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 25th, 2003, 07:50 PM
Registered User
 
Join Date: Nov 2003
Location: , , USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code translation

Hello,

byte data is declared and initialized to 1

 How should I read the following line: data *= 2; // Multiply by 2. Can this be translated 1*2=2(1x2=2)? Second line below meaning 2*2=4?
I don't understand how data *=2 should be translated and/or read.


Thanks

//Chapter 2, Exercise 1
public class ByteTest { // Ensure classes/variables have distinctive names.
public static void main(String args[]) {
    // Initialize variable data of type byte to 1:
    byte data = 1;

    data *= 2; // Multiply by 2
    data *= 2; // Multiply by 2: 1st time data is equal to 1 times two equals two
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 2nd time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 3rd time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 4th time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 5th time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 6th time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 7th time
    System.out.println("data = " + data);
  #2 (permalink)  
Old November 28th, 2003, 07:50 PM
Registered User
 
Join Date: Nov 2003
Location: , , USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I've figureed this out.
It has to do with: The op=Operators.
byte data is declared and initialized to 1
data *=2 is the same as data = data *2
So the Byte data with value of 1*2=2.
So the consequent succession in code above doubles
(viz 1*2,2*2,2*4,2*8)
  #3 (permalink)  
Old December 1st, 2003, 07:55 AM
Authorized User
 
Join Date: Sep 2003
Location: den Haag, , Netherlands.
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Where's my "Edit" gone?????
(My login was confirmed, but later not recognized)

  #4 (permalink)  
Old December 3rd, 2003, 11:08 AM
Registered User
 
Join Date: Nov 2003
Location: , , USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

(Wed. 12/3/03) Thank you

Quote:
quote:Originally posted by freezotic
 that's right

//Chapter 2, Exercise 1
public class ByteTest { // Ensure classes/variables have distinctive names.
public static void main(String args[]) {
    // Initialize variable data of type byte to 1:
    byte data = 1;

    data *= 2; // Multiply by 2
    data *= 2; // Multiply by 2: 1st time data is equal to 1 times two equals two
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 2nd time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 3rd time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 4th time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 5th time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 6th time
    System.out.println("data = " + data);
    data *= 2; // Multiply by 2: 7th time
    System.out.println("data = " + data);



[/quote]

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java to C# translation vinny4545 Servlets 3 September 4th, 2015 12:37 PM
Code translation from ASP to C# motemape ASP.NET 2.0 Basics 0 May 27th, 2007 12:01 PM
i18n Translation jagadeesh BOOK: Expert One-on-One J2EE Design and Development 0 June 13th, 2006 08:18 AM
Spanish to English!Code Translation Help C++ jigen7 C++ Programming 0 March 30th, 2006 12:28 AM
java to C# translation vinny4545 ASP.NET 1.0 and 1.1 Professional 0 July 2nd, 2004 07:19 PM



All times are GMT -4. The time now is 10:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.