Note that there are some explanatory texts on larger screens.

plurals
  1. POJava How Do I Properly Return Int Value?
    primarykey
    data
    text
    <p>Total novice here trying to learn myself java with tools online. Right now Im clearly doing something wrong as I cant figure out how to get a separate class file to return a random int. The random code is fine, its just I don't know how to actually get it to return properly! Probably seems like java 101 to a lot of you but im lost. lol</p> <p>I want them in seperate class files as an excersize in how to not put everything in one file. This workd fine if I just put it in one class, but thats not what I want to practice here. Thanks for any help!</p> <p>Class file 1:</p> <pre><code>package whatsthis; import java.util.Random; import java.util.Scanner; public class Noidea{ private static Scanner user_input; public static void main(String[] args) { System.out.println("Git is awesome"); Scanner user_input = new Scanner(System.in); randnum rn = new randnum(); System.out.println("RANDOM NUM: " +rn); System.out.println("What is your name?"); String first_name; first_name = user_input.next(); System.out.println("Hello, "+first_name); int health = 100; while( health&gt;0 ) { //System.out.println(rndNum); //System.out.println(rndNum); System.out.println(health); System.out.println("Attack? Y/N"); String attack; attack = user_input.next(); if (attack.equals("Y")){ System.out.println("KILL!"); System.out.println("You've done " + rn + " damage!"); //health = health - rn; System.out.println(health); } else { System.out.println("cower.."); } } } } </code></pre> <p>Class file 2:</p> <pre><code>package whatsthis; import java.util.Random; public class randnum { public int randnum() { int Low = 10; //Used for lowened number in random int High = 15; //Used for highend number in random Random rndGen = new Random(); //Declare a new 'random' object int rn = rndGen.nextInt(High-Low) + Low; //Proper random between two numbers (high and low) return rn; } } </code></pre> <p>Instead of the number im looking for, it returns <strong>whatsthis.randnum@2d09b23b</strong> Why ios this and how do I fix it? Sorry again if this is painfully simple. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload