0

I was hoping that someone could show me how to use the equals method to change numbers that were entered. Three numbers are entered and the user is asked if they need to change a number. This is followed by a yes or no. It says if the answer is yes to change the number, to use the equals method. This is donethree times by once changing the number, adding a number and removing a number. Please help! Thanks Ytula

2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by server_crash
0

Your question is somewhat unclear. But maybe I got it right. I posted code what I thought you were wanting if it's not let me know...

import java.io.*;

class NumbersandInput
{
 public static void main(String[] args) throws IOException
 {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 	String inData;
	int i;
	int i2;

	System.out.println("Please enter an integer");
	i = Integer.parseInt(br.readLine());
	i2 = i;
	System.out.println("\n Would you like to change the number?");

	inData = br.readLine();
	if (inData.equals("Yes"))
	   {
		try {
			System.out.println("\n What would you like to change it to?");
			i2 = Integer.parseInt(br.readLine());
		    }
		    catch (NumberFormatException e) {}
           }
	   else {
			System.out.println("No change was made");
		}

	System.out.println(" \n \n \n The staring value of the integer was: " + i);
	System.out.println(" The eding value of the integer was: " + i2);


 }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.