Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
|
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 April 8th, 2004, 09:39 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default What´s wrong with my code???

public class MyJavaStudy
{
public static void main(String[] args)
{
     String resolution = "I am halfway, so ";
    
     JavaBook:
     do
     {
         System.out.print(resolution);
         resolution = "I will ";
         continue JavaBook;
     }
     while((new java.util.Random()).nextGaussian() < 10);
    
     System.out.println("not despair");
}
}
 
Old April 9th, 2004, 04:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Depends. What do you want it to do?

The most obviously suspicious aspect is that you have a label, "JavaBook", which you always continue to within the body of your do..while() loop.

Therefore, you will never execute the while() conditional, so your loop lasts forever, and you'll never see "not despair".


Take care,

Nik
http://www.bigaction.org/
 
Old April 11th, 2004, 08:53 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by nikolai
 Depends. What do you want it to do?

http://www.bigaction.org/
Hi, Nikolai!
Are you the new moderator?
Do you answer my questions?
There's nobody else here, but I will be visiting once a week.

The program was a poem, that should have kept me motivated to finish the booK.

But now you are here!
I still got some two questions without answers posted here...
Will you look at them???

Greetings from Holland!
Frans Lelieveld

You have a fine CV, Nik!

 
Old April 20th, 2004, 10:33 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

import java.util.Random; // to all students..

public class TryJavaStudy // of Horton's book
{
public static void main(String[] args) // the main thing is..
{
     Random teacher = new Random(); // to stick
     Random student = new Random(); // to it!
    
     String resolution = "You've just begun, so ";
    
     do // beginning Java 2
     {
         System.out.print(resolution);
         resolution = "please "; // continue Java 2
         student.setSeed(teacher.nextLong());
     }
     while(student.nextGaussian() < 2); // to master Java 2
    
     System.out.println("don't despair"); // take Gauss's advice
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with my code? DyerOppenheimer BOOK: Beginning Ajax with ASP.NET 0 January 7th, 2008 08:46 AM
What's wrong with this code jack123 SQL Server 2000 4 July 11th, 2007 12:09 PM
what's wrong with this code? hertendreef Visual Basic 2005 Basics 0 March 2nd, 2007 10:29 AM
what´s with this error kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 September 19th, 2006 02:32 PM
what's wrong with this code? miguel.ossa ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2004 11:33 AM





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