Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 764697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:46:11+00:00 2026-05-14T16:46:11+00:00

I have just started to learn the very basics of Java programming. Using a

  • 0

I have just started to learn the very basics of Java programming. Using a book entitled “Programming Video Games for the Evil Genius”.

I have had an Illegal Start of Expression error that I can’t for the life of me get rid of. I have checked the sample code from the book and mine is identical.

The error is coming from the for(int i = difficulty; i >= 0; i- – ) line.

Thanks for helping a newbie out.

import javax.swing.*;

public class S1P4

   {public static void main(String[] args) throws Exception {

    int difficulty;
    difficulty = Integer.parseInt(JOptionPane.showInputDialog("How good are you?\n"+
            "1 = Great\n"+"10 = Terrible"));

    boolean cont = false;

    do
    {

        cont = false;

        double num1 = (int)(Math.round(Math.random()*10));

        double num2;
        do
        {
            num2 = (int)(Math.round(Math.random()*10));
        }
        while(num2==0.0);

        int sign = (int)(Math.round(Math.random()*3));

        double answer;

        System.out.println("\n\n*****");

        if(sign==0)
        {
            System.out.println(num1+" times "+num2);
            answer = num1*num2;
        }
        else if(sign==1)
        {
            System.out.println(num1+" divided by"+num2);
            answer = num1/num2;
        }
        else if(sign==1)
        {
            System.out.println(num1+" plus "+num2);
            answer = num1+num2;
        }
        else if(sign==1)
        {
            System.out.println(num1+" minus "+num2);
            answer = num1-num2;
        }
        else
        {
            System.out.println(num1+" % "+num2);
            answer = num1%num2;
        }

        System.out.println("*****\n");

        for(int i = difficulty; i >= 0; i- - )

        {
            System.out.println(i+"...");

            Thread.sleep(500);
        }
        System.out.println("ANSWER: "+answer);

        String again;
        again = JOptionPane.showInputDialog("Play again?");

        if(again.equals("yes"))
            cont = true;
    }

    while(cont);

}
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:46:12+00:00Added an answer on May 14, 2026 at 4:46 pm

    You had accidentally introduced a space, separating the -- (JLS 15.14.3 Postfix decrement operator) into two tokens - -. This is what caused the syntax error.

    By the way, if this code as written is even close to identical to what’s in the book, then I suggest getting another book. That code is horribly written. The if-else are ineffective: the third case and beyond are unreachable.

    Let’s also look at this code:

    int sign = (int)(Math.round(Math.random()*3));
    

    So… we want a random int between 0..3? Why not use java.util.Random.nextInt(int n)?

    Not to mention, if we’re going to switch (JLS 14.11) on sign, don’t we need 5 different values instead of 4? Since there are 5 operators?

    And that’s just the obvious logical errors. There are many stylistic problems with the code as well.

    Horrible book.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming "parent" is an Ext.form.Field, you could use createSequence on… May 17, 2026 at 2:58 am
  • Editorial Team
    Editorial Team added an answer The only way to get it working is to make… May 17, 2026 at 2:58 am
  • Editorial Team
    Editorial Team added an answer They are somewhat related but there's a subtle difference. Atomicity… May 17, 2026 at 2:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have started to do some programming using VIM. I have very mixed feelings
I have just started to learn Ruby and got a good take on the
I want to use xxdiff for my merging needs. I have just started using
I'm new to using Linq and just started a side project to learn some
I'm very new to programming and I'm just starting to learn VBA with excel.
I have just started to learn Haskell out of interest. I follow learnyouahaskell.com .
I have just started the MIT Introduction to Algorithms course through the material posted
Greetings, everyone. I'm trying to learn some Silverlight basics, and have decided to write
This should be very simple question. There are many programming languages out there, compiled
i know HTML/CSS and want to learn WPF styling. how can i get started.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.