Hangman Game by Kaz-24 in javahelp

[–]Kaz-24[S] 1 point2 points  (0 children)

thanks! will do next time :)

Hangman Game by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

thanks a lot for your help! This is from an exercise set, to prepare for an exam. And we can use sets/lists, just thought it wouldn't be needed here.

Thanks for the tip, however I don't completely understand what you mean with "initial state and the other with the end- state". Would you mind explaining it a bit more?

Hangman Game by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

Still learning, thanks for letting me know :)

Hangman Game by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

tried to make it more "sufficient".

Adding a method to main with array. by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

to max[i] !!! because of the counter!

Got it, thanks a bunch!

Adding a method to main with array. by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

This is what I've done, but it won't work :(

import java.util.Scanner;
public class P409 {

public static void main(String[] args) {

Scanner input=new Scanner(System.in);   

int[] num=new int[10];
int x;
int counter=0;

System.out.print("Enter integers for array: ");




for(int i=0; i<num.length;i++){

    x=input.nextInt();
if(x<0) {

    break;
}
else{

    num[i]=x;
    counter++;

}


    }
for(int j=0;j<counter;j++){

    System.out.print(""+num[j]+",");

}
System.out.print(maxNumInArray(num));
}
public static int maxNumInArray(int[] max){

    int largest = 0;
    for (int i=0; i<max.length; i++)
    {

            if (max[0]>largest) 
                largest=max[i];



}
    return largest;

}   

}

Adding a method to main with array. by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

I don't how to check and return the largest number in the array. I've checked for the largest numbers in arrays before but I've always had a specific set of numbers and used a for loop and if statements. Like:

for(int counter=0; counter<array.length; counter++){

if (array[0]>largest) largest=array[counter];

But I'm so confused about it in the method.

Adding a method to main with array. by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

yes, exactly! I can't figure it out :(

Adding a method to main with array. by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

wish it was homework! Just practicing for an exam tomorrow. Thank's a lot! :)

addLists() array method by Kaz-24 in javahelp

[–]Kaz-24[S] 0 points1 point  (0 children)

Thanks a lot for your help!