| | |
Cannot incorporate equals method for a yes or no answer.
![]() |
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 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
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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...
Java Syntax (Toggle Plain Text)
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); } }
![]() |
Similar Threads
- String.equals() (Java)
- Difference between Endswith() and Equals() Method? (C#)
- using equals to compare with inhertance (Java)
- <jsp:forward> problems (Java)
- Java Help Needed....... (Java)
- difference b/w equals and == (Java)
Other Threads in the Java Forum
- Previous Thread: java client server quiz. interesting!!!
- Next Thread: output numbers from a varible on different lines asap
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class client code compile compiler component database development digit eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying pearl problem program programming project qt recursion scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver string superclass swing system text-file thread threads tree variablebinding windows xor






