Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old October 4th, 2008, 04:47 AM
Newbie
 
Join Date: Oct 2008
Location: NY
Posts: 4
Default Help please

I was writing a simple programs on arrays and i dont know why these error pop up if some can explain what im doing wrong

public class CoinValues {
public static void main(String[] args) {
int[] coinValue = {5,10,25};
String[] coinWord = {"nickels","dimes","quarters"};

int count = IB.inputInt("How many coins do you have? ");
int i = IB.inputInt("Enter 0 for nickels, 1 for dimes, 2 for quarters: ");

int cent = int count * int[i];

IB.output(count + " " + int[i] + " equals " + .cent + "cents.");

}
}

C:\IBCS\CoinValues.java:11: '.class' expected
int cent = int count * int[i];
^
C:\IBCS\CoinValues.java:13: ']' expected
IB.output(count + " " + int[i] + " equals " + .cent + "cents.");
^
C:\IBCS\CoinValues.java:13: '.class' expected
IB.output(count + " " + int[i] + " equals " + .cent + "cents.");
^

class expected?
and i dont know why i need a ]
if some can explain
oh the purposee is to find the value in cents of coins of one type
Reply
  #2  
Old October 4th, 2008, 01:05 PM
JosAH's Avatar
Moderator
 
Join Date: Mar 2007
Location: Voorschoten, the Netherlands
Age: 52
Posts: 8,760
Default

First a few remarks: as you have seen in your original post the code didn't show
up correctly (no indentation). The forum software removes leading spaces in every
line except for lines (even a bunch of lines) embraced by [code] ... [/code]
tags. The error messages in your post could've looked like this:

Expand|Select|Wrap|Line Numbers
  1. C:\IBCS\CoinValues.java:11: '.class' expected
  2.         int cent = int count * int[i];
  3.                                       ^
  4. C:\IBCS\CoinValues.java:13: ']' expected
  5.     IB.output(count + " " + int[i] + " equals " +  .cent + "cents.");
  6.                                     ^
  7. C:\IBCS\CoinValues.java:13: '.class' expected
  8.     IB.output(count + " " + int[i] + " equals " +  .cent + "cents.");
  9.                                                                                 ^
  10.  
  11. class expected?
  12.  
As you can see the caret ends up somewhere where you have seen it on your
screen as well instead of on the left side of the text. There's even no need to
remember this because when you compose your message you'll find a little
legend telling the same thing.

Now on to your compiler error diagnostics: what you fed to your compiler isn't
Java, it is nonsense to the compiler. Have a look:

Expand|Select|Wrap|Line Numbers
  1.         int cent = int count * int[i];
This defines an int variable 'cent' and you want to initialize it (the '=' sign introduces
an initializing value). But what is 'int count'? That doesn't yield a value which can
be converted to an int. There are too many errors in your code attempt to discuss
here. Read the first post in this forum named "Read This First". It contains a link
where you can download Sun's Java tutorial. I strongly advise you to download it
all and read it before you try to write some Java code. Programming is not guessing
what the language is supposed to be or hoping for what it should be.

kind regards,

Jos (moderator)
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.