Connecting Tech Pros Worldwide Forums | Help | Site Map

Help please

Newbie
 
Join Date: Oct 2008
Location: NY
Posts: 4
#1: Oct 4 '08
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

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Oct 4 '08

re: Help please


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