x.øi5orked through most of this program i just have a couple questions. a)How can i declare a new…

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Order a Similar Paper HERE Order a Different Paper HERE

x.øi5orked through most of this program i just have a couple questions.

a)How can i declare a new variable diff and assign to it the absolute value of (num – guess). To find the absolute value you need to usethe method abs in the Math class: Math.abs(num – guess)

(b) If Diff is 0 then the user guessed the correct number

(c) If Diff is not 0 then use the following logic to help the user guesses the number faster.

import javax.swing.*;

public class guess

{

public static void main (String[] args)

{

//declare the variables

int num; //variable to store therandom number

int guess; //variable to store thenumber guessed by the user

String strGuess;

boolean done; //boolean variable to control the loop

num = (int) (Math.random() *100);

done =false;

while(!done)

{

strGuess=JOptionPane.showInputDialog(“Enter an Integer:n ” +

“greater than or equal zero and less than a hundred”);

guess =Integer.parseInt(strGuess);

System.out.println();

if (guess ==num)

{

JOptionPane.showMessageDialog(null,”You guessed the”

+ “correct number.”);

done =true;

}

else

if (guess

JOptionPane.showMessageDialog(null,”Your guess is ”

+ “lower than ”

+ “the number.n”

+ “Guess again!”);

&nbs õbpx.øi5bsp;else

JOptionPane.showMessageDialog(null,”Your guess is ”

+ “higher than ”

+ “the number.n”

+ “Guess again!”);

} //endwhile

}}

(üx.øi5x.øi5