Note that there are some explanatory texts on larger screens.

plurals
  1. POError with methods and while loop in java
    primarykey
    data
    text
    <p>I have problem with "compareMethod" and with the while loop, so if anyone has any idead how to help me i would be grateful thank you. I am using Eclipse as an Ide.</p> <p>I want to enter three values and then to print the smallest one.</p> <p>Here is my code:</p> <pre><code>import java.util.Scanner; public class CompareValues { public static void main( String[] args ) { System.out.println(); System.out.println( "The smallest number is: " ); int first; int second; int third; checkMethod( first, second, third ); } static int checkMethod( int firstNumber, int secondNumber, int thirdNumber ) { Scanner input = new Scanner( System.in ); System.out.println( "Enter three nubmers between 1 - 100: " ); firstNumber = input.nextInt(); secondNumber = input.nextInt(); thirdNumber = input.nextInt(); if ( ( 0 &lt; firstNumber ) || secondNumber || ( thirdNumber &gt; 100 ) ) { System.out.println( "Invalid entry: enter numbers between 1 and 100 only: " ); } } static int compareMethod( int first, int second, int third ) { if ( ( first &lt; second ) &amp;&amp; ( first &lt; third ) ) { return first; } else if ( ( second &lt; first ) &amp;&amp; ( second &lt; third ) ) { return second; } else { return third; } } } </code></pre> <p>When I compiled the code I got this message:</p> <blockquote> <p>Exception in thread "main" java.lang.Error: Unresolved compilation problems: The local variable first may not have been initialized The local variable second may not have been initialized The local variable third may not have been initialized at CompareValues.main(CompareValues.java:11) </p> </blockquote>
    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