Connecting Tech Pros Worldwide Help | Site Map

Help please

  #1  
Old October 4th, 2008, 04:47 AM
Newbie
 
Join Date: Oct 2008
Location: NY
Posts: 4
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
  #2  
Old October 4th, 2008, 01:05 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Please!!! Adding 5 Days to another Date in an access query uno7031 answers 0 August 6th, 2009 01:16 PM
Big DataGrid Update Problem-MVP Help Please???? steroche answers 4 November 19th, 2005 06:26 PM
Help Please Jason answers 23 November 15th, 2005 02:55 PM
Quick help please with FRAMES (another question) TrvlOrm answers 14 July 23rd, 2005 11:51 AM
Oracle to Mysql (dates) Help please duikboot answers 5 July 18th, 2005 08:35 AM