Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 25th, 2003, 07:50 PM
Registered User
 
Join Date: Nov 2003
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);
 
Old November 28th, 2003, 07:50 PM
Registered User
 
Join Date: Nov 2003
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)
 
Old December 1st, 2003, 07:55 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old December 3rd, 2003, 11:08 AM
Registered User
 
Join Date: Nov 2003
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]






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.