abdulrehmansuleman's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 4 (0.02 per day)
- Joined:
- 09-October 12
- Profile Views:
- 48
- Last Active:
Oct 10 2012 10:22 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Restarting the code using while loop and System.exit(0)
Posted 9 Oct 2012
fromTheSprawl, I found your explanation quite helpful. So, what I understand that integer is a primitive type of variable and all primitive types of variables are compared by value even if we use == which compares by reference. And for strings, I should use .equals().
But I am still confused as to what "reference" means in java. What is a reference? And when we say that == compares references instead of actual values, what is it actually comparing if not value?
CasiOo: Can you explain what you mean by "hashcode" of the object? And how is it different from the value of the object? -
In Topic: Restarting the code using while loop and System.exit(0)
Posted 9 Oct 2012
If I replace == with .equals("no"), it does work and the program ends. But I don't get why it works. Doesn't == mean that if the value of string is "no" (the person types no), it should terminate the program, like I want? Or does == imply something else. Also why does == work fine with integer but gives me a problem when I attempt to use string? Actually I just want to understand my mistake, so you'll have to excuse me if I am asking a very obvious question. -
In Topic: Restarting the code using while loop and System.exit(0)
Posted 9 Oct 2012
Here's the whole code
import java.util.Scanner; public class Addloops { public static void main (String[]args) { Scanner scan=new Scanner(System.in); boolean b=true; while (B)/> {System.out.println ("How many numbers do you want to add to one another?"); int x=scan.nextInt(); int y=0; System.out.println ("Enter " + x + " numbers"); for (int i=0;i<x;i++) { int z=scan.nextInt(); y=y+z;} System.out.println ("Your answer is " + y); System.out.println ("Thank you for using the software"); System.out.println ("Do you want to use the software again? yes or no?"); Scanner s=new Scanner(System.in); String a=s.nextLine(); if (a=="no") {System.exit(0);}} }}
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Click here to e-mail me
Friends
abdulrehmansuleman hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
abdulrehmansuleman has no profile comments yet. Why not say hello?