Help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheHav
    New Member
    • Oct 2008
    • 4

    #1

    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","dim es","quarters"} ;

    int count = IB.inputInt("Ho w many coins do you have? ");
    int i = IB.inputInt("En ter 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\CoinVal ues.java:11: '.class' expected
    int cent = int count * int[i];
    ^
    C:\IBCS\CoinVal ues.java:13: ']' expected
    IB.output(count + " " + int[i] + " equals " + .cent + "cents.");
    ^
    C:\IBCS\CoinVal ues.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
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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:

    Code:
    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?
    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:

    Code:
    		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)

    Comment

    Working...