This site requires JavaScript, please enable it in your browser!
Greenfoot back
LearningProgramming
LearningProgramming wrote ...

2013/4/20

Using Arrays in Java.....

for (int counter = 1; counter < temp.length; counter++)
		{
		    if (temp[counter] < low)
		    {
		        low = temp[counter];
		    }
		}  
		System.out.println("The lowest Temperature is: " + low);
		
Is this a correct syntax of getting a minimum value of an array? Need some help please!
Mano_pesada Mano_pesada

2013/4/20

#
its fine but first "low" must take a value included in the list otherwise if it stats at 0 will not work
Gevater_Tod4711 Gevater_Tod4711

2013/4/20

#
The starting value of counter should be 0 because the first field of an array is accessible by 0 and not by 1.
Mano_pesada Mano_pesada

2013/4/20

#
true i missed that one
danpost danpost

2013/4/20

#
The code is fine. You just need to set 'low' to the first item on the list before the loop:
low = temp[0]; // add this line
for (int counter=1; counter<temp.length; counter++)
{
    // etc.
Thanks al ot guys....
Does anyone have an idea how to create a blackjack game?
JetLennit JetLennit

2013/4/22

#
danpost danpost

2013/4/22

#
I do not think I would have much trouble with one.
@Gevater_Tod4711 let's say one is creating with eclipse do i need to have a class for each cards?
@danpost with creating the card games?
danpost danpost

2013/4/23

#
No. You can use one class to create all the cards with. You just need one instance integer field that can be a unique number from zero to fifty-one to distiguish between each card and one boolean field to track whether the card is flipped up or not. The number and suit of the cards can be determined by: value = cardNumber % 13; (0=ace, 1=two, 2=three, ... 9=ten, 10=Jack, 11=Queen, and 12=King) suit = (cardNumber - value) / 13; (0=club, 1=diamond, 2=heart, and 3=spade)
@danpost you know how it is 21, well this one is 33 so am kinda lost with those numbers!
danpost danpost

2013/4/23

#
All I am doing is giving a unique number between zero and fifty-one to each card in the deck. The specific card can be determined from that unique number as described below: 0 to 12 are the Ace of clubs through the King of clubs 13 to 25 are the Ace of diamonds through the King of diamonds 26 to 38 are the Ace of hearts through the King of hearts 39 to 51 are the Ace of spades through the King of spades This unique assigned number can also be used to determine which image to apply to the card when it is showing. It matters not if you are doing 21, 33, or whatever. It is just a decent way to set up the Card class to create the cards and be able to tell which card is which by its uniquely assigned number. The number can also be used in creating the filename of the image to use for the card.
Gevater_Tod4711 Gevater_Tod4711

2013/4/23

#
@LearningProgramming Like danpost already said you don't need a class for any card. In my Black Jack game you can see that I just changed the values of the cards and used one card. But if you try to programm this using eclipse that will be realy complicated because eclipse at all is not easy to use and it hasn't got a graphical surface like in greenfoot. Also there are no acting cycles... You would have to do everything by yourself. So you better try to create this game using Greenfoot.
You need to login to post a reply.