|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Java Question [HELP!]
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
4.0 GHz
|
Code:
import java.util.*;
public class test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
prompt(s);
}
public static void prompt(Scanner s) {
int num = 1;
System.out.print("Write something: ");
String something = s.nextLine();
System.out.println(something);
boolean test = something == "lol";
while(test) {
System.out.println("in the while loop" + num + " times!");
num++;
System.out.print("Write something: ");
something = s.nextLine();
}
}
}
__________________
AMD Phenom 9500 2.475ghz = http://valid.x86-secret.com/show_oc.php?id=429024![]() AMD Phenom 9950 3.208ghz http://valid.x86-secret.com/show_oc.php?id=452106![]() Intel Core i7 920 3.809ghz = http://valid.canardpc.com/show_oc.php?id=540721![]()
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
4.0 GHz
|
I think i figurred it out... Strings have to be compared using .equal() object
__________________
AMD Phenom 9500 2.475ghz = http://valid.x86-secret.com/show_oc.php?id=429024![]() AMD Phenom 9950 3.208ghz http://valid.x86-secret.com/show_oc.php?id=452106![]() Intel Core i7 920 3.809ghz = http://valid.canardpc.com/show_oc.php?id=540721![]()
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
"Ghetto Solutions"
![]() |
This. You cannot compare strings via ==, it's just wrong.
__________________
Please support the Modern Warfare 2 boycott until our voices are heard! ![]() Modern Warfare 2 Petition Global Modern Warfare 2 Price Hike Modern Warfare Will Not Have Servers, Mods, Anything Have you canceled your pre-order?
|
|||||||||||||
|
|
|
|
#4 (permalink) |
|
Programmer
|
I believe what you are looking for is
Code:
boolean test = something.equals("lol");
Code:
boolean test = something.equalsIgnoreCase("lol");
|
|
|
|
|
|
#5 (permalink) | |||||||||||||
|
WaterCooler
![]() |
Quote:
__________________
|
|||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||||
|
Programmer
|
Looks like you have a fundamental misunderstanding of the logical operators, primitives and the way they can and can't interact. Probably need to dedicate a little more time to reviewing that stuff, it's more important then getting up on all the different methods and utils.
__________________It's good you were able to find some code to fix the problem, that's also an important aspect, but get the basics down too!!! And first!!!! All that boring stuff is what lays the foundation for good OO, and that's the most important thing for anyone wanting to be a programmer.
|
|||||||||||
|
|
|
|
|
#7 (permalink) | ||||||||||||||
|
4.0 GHz
|
Quote:
I just never really realized Strings were an object (they are captialized "S"trings which makes them an object) this being only my second programing course yet. Also, new problem i'm encountering Code:
while(!(again.toLowerCase().startsWith("y")) || !(again.toLowerCase().startsWith("n"))) {
again = playAgainPrompt(s);
}
Thanks guys, -Falven
__________________
AMD Phenom 9500 2.475ghz = http://valid.x86-secret.com/show_oc.php?id=429024![]() AMD Phenom 9950 3.208ghz http://valid.x86-secret.com/show_oc.php?id=452106![]() Intel Core i7 920 3.809ghz = http://valid.canardpc.com/show_oc.php?id=540721![]()
Last edited by falven : 2 Weeks Ago at 05:29 AM |
||||||||||||||
|
|
|
|
|
#8 (permalink) | |||||||||||||
|
4.0 GHz
|
bump
__________________
AMD Phenom 9500 2.475ghz = http://valid.x86-secret.com/show_oc.php?id=429024![]() AMD Phenom 9950 3.208ghz http://valid.x86-secret.com/show_oc.php?id=452106![]() Intel Core i7 920 3.809ghz = http://valid.canardpc.com/show_oc.php?id=540721![]()
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|