File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
i am not able to get out put of this program
vijayreddy patil
Greenhorn
Joined: Feb 12, 2008
Posts: 5
posted
Mar 11, 2008 13:25:00
0
public class SimpleDotCom { int [] locationCells; int numOfHits = 0; public void setLocationCells(int [] locs) { locationCells = locs; } public String checkYourself(String stringGuess) { int guess = Integer.parseInt(stringGuess); String result="miss"; for ((int cell : locationCells) { if (guess == cell) { result="hit"; numOfHits++; break; } } if(numOfHits == locationCells.length) { result = "kill"; } return result; } } public class SimpleDotComTestDrive { public static void main(String[] args) { SimpleDotCom dot = new SimpleDotCom(); int[] locations={2,3,4}; dot.setLocationCells(locations); String userGuess= "2"; String result =dot.checkYourself(userGuess); System.out.println(result); } }
Edit by mw:
Added
Code Tags
.
[ March 11, 2008: Message edited by: marc weber ]
Nicholas Jordan
Ranch Hand
Joined: Sep 17, 2006
Posts: 1282
posted
Mar 11, 2008 14:29:00
0
in main()
for(int cell : locationCells)
if( cell != 0) System.out.println( Integer.toString(cell));
Or something of that nature.
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
I like...
posted
Mar 11, 2008 17:37:00
0
Welcome to JavaRanch!
Your code won't compile because there is an extra parenthesis in this line...
for ((int cell : locationCells) ^ extra opening parenthesis
After fixing that, your code should compile and run with output.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award."
~Joe Strummer
sscce.org
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: i am not able to get out put of this program
Similar Threads
Enhanced for loop
Help compiling Program
Head first Java; simpledotcom problems...
i am still getting compile time error in this program plz give me solution
Test class cannot find other class
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter