Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 2 Weeks Ago   #1 (permalink)
4.0 GHz
 
falven's Avatar
 
intel ati

Join Date: Sep 2008
Location: Florida
Posts: 627

Rep: 23 falven is acknowledged by some
Unique Rep: 20
Trader Rating: 0
Default Java Question [HELP!]

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();
		}
	}
	
	
	

}
Why wont it go into the freaking while loop when i type lol! I really am so frustrated right now and can't figure out why.... Please help.

System: Compi
CPU
Intel Core i7 920 @ 3.8 1.35V
Motherboard
Evga X58
Memory
G.Skill 3Gb DDR3 1600 Triple Channel
Graphics Card
Asus EAH4850
Hard Drive
2X OCZ Vertex 30GB Raid 0 + WD VelociRaptor 300GB
Sound Card
SoundBlaster X-FI Extreme Audio
Power Supply
Antec TruePower Trio TP3-650
Case
Modded Antec Three Hundred Black ATX Mid Tower
CPU cooling
XIGMATEK HDT-S1283 + Scythe "ULTRA KAZE"
GPU cooling
Glaciator Fansink
OS
Windows Vista X64/Windows 7
Monitor
Vizio 22" HD 1080P TV
falven is offline   Reply With Quote
Old 2 Weeks Ago   #2 (permalink)
4.0 GHz
 
falven's Avatar
 
intel ati

Join Date: Sep 2008
Location: Florida
Posts: 627

Rep: 23 falven is acknowledged by some
Unique Rep: 20
Trader Rating: 0
Default

I think i figurred it out... Strings have to be compared using .equal() object

System: Compi
CPU
Intel Core i7 920 @ 3.8 1.35V
Motherboard
Evga X58
Memory
G.Skill 3Gb DDR3 1600 Triple Channel
Graphics Card
Asus EAH4850
Hard Drive
2X OCZ Vertex 30GB Raid 0 + WD VelociRaptor 300GB
Sound Card
SoundBlaster X-FI Extreme Audio
Power Supply
Antec TruePower Trio TP3-650
Case
Modded Antec Three Hundred Black ATX Mid Tower
CPU cooling
XIGMATEK HDT-S1283 + Scythe "ULTRA KAZE"
GPU cooling
Glaciator Fansink
OS
Windows Vista X64/Windows 7
Monitor
Vizio 22" HD 1080P TV
falven is offline   Reply With Quote
Old 2 Weeks Ago   #3 (permalink)
"Ghetto Solutions"
 
AMD+nVidia's Avatar
 
intel nvidia

Join Date: Apr 2006
Location: My Room
Posts: 6,203

Rep: 298 AMD+nVidia is a proven memberAMD+nVidia is a proven memberAMD+nVidia is a proven member
Unique Rep: 232
Folding Team Rank: 52
Trader Rating: 15
Default

Quote:
Originally Posted by falven View Post
I think i figurred it out... Strings have to be compared using .equal() object
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?

System: WaterWorks
CPU
Core 2 Quad Q6700 (3.79GHz)
Motherboard
ASUS Maximus Formula X38
Memory
6GB Dual Channel PC6400 5-4-4-12 (800MHz)
Graphics Card
PNY XLR8 GTX280 1024MB
Hard Drive
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare
Sound Card
Modded Creative X-Fi XtremeMusic
Power Supply
Corsair 900w
Case
Cooler Master Cosmos 1000 (Modded)
CPU cooling
Custom V6 Stinger *Lapped*
GPU cooling
Stock
OS
Windows 7 Ultimate x64
Monitor
I-INC 28" HDMI 1920x1200
3 Million+ Folding at Home points
AMD+nVidia is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 2 Weeks Ago   #4 (permalink)
Programmer
 
Metruzero's Avatar
 
Join Date: Oct 2009
Location: In a box
Posts: 8

Rep: 0 Metruzero Unknown
Unique Rep: 0
Trader Rating: 0
Default

I believe what you are looking for is

Code:
boolean test = something.equals("lol");
OR if you want it to ignore capitals

Code:
boolean test = something.equalsIgnoreCase("lol");
Metruzero is offline   Reply With Quote
Old 2 Weeks Ago   #5 (permalink)
WaterCooler
 
om3n's Avatar
 
intel nvidia

Join Date: Mar 2008
Posts: 1,819

Rep: 82 om3n is acknowledged by some
Unique Rep: 69
Trader Rating: 7
Default

Quote:
Originally Posted by Metruzero View Post
I believe what you are looking for is

Code:
boolean test = something.equals("lol");
OR if you want it to ignore capitals

Code:
boolean test = something.equalsIgnoreCase("lol");
there ya go. I'm so happy I have OCN to help me with programming as well
__________________
*CPUZ validation 3.6 GHZ*
Quote:
Originally Posted by DuckieHo View Post
I rather have a naked picture of it... or at least it's backside.
Quote:
Originally Posted by VincentJ View Post
OM3N I hereby declare you OCN's most 1337 OCer.

System: om3n rev. 2.7.9 *REVIVED* stock clocks for now...
CPU
Intel Q6600 quad core @ 3.6 GHZ/ 3.2 GHZ constant
Motherboard
eVGA 790i Ultra SLI
Memory
(4 x 1056MB) Corsair DDR3 XMS 1333 @ 1511
Graphics Card
eVGA 9800 GTX x2 SLI @ 800/2000/1200
Hard Drive
2x 150GB 10K WD raptors RAID0; seagate 500GB
Power Supply
Thermaltake 1200 watt toughpower
Case
Thermaltake Armor
CPU cooling
D-TEK FuZion
GPU cooling
Swiftech MCW60-R2 x2 + 2x iandh custom heat sinks
OS
Windows 7 build 7000 (soon to be full release)
Monitor
Samsung 226BW 22" x2
om3n is offline   Reply With Quote
Old 2 Weeks Ago   #6 (permalink)
Programmer
 
Half_Duplex's Avatar
 
amd ati

Join Date: Oct 2009
Location: Orlando
Posts: 72

Rep: 4 Half_Duplex Unknown
Unique Rep: 4
Trader Rating: 0
Default

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.
__________________
System: Lecutis 4
CPU
AMD Athlon II X4 620 2.6GHz
Motherboard
ASUS Evo 790X AM3
Memory
2x2gb G.Skill 1600
Graphics Card
Radeon HD 5770
Hard Drive
2 x WD Black 250, 1 x WD 100
Sound Card
ASUS
Power Supply
Earthwatts 650
Case
XClio WindTunnel BLK
OS
XP, Win 7 64, SUSE 11:Gnome, Sulphur:KDE, Solaris
Monitor
2 x LG 21" WS LCD
Half_Duplex is offline   Reply With Quote
Old 2 Weeks Ago   #7 (permalink)
4.0 GHz
 
falven's Avatar
 
intel ati

Join Date: Sep 2008
Location: Florida
Posts: 627

Rep: 23 falven is acknowledged by some
Unique Rep: 20
Trader Rating: 0
Default

Quote:
Originally Posted by Half_Duplex View Post
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.
I do know most of the fundamentals, I think?
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);
        }
What im trying to do is make it so it does again = playAgainPrompt(s); if again.toLowerCase().startsWith("y") does NOT start with "y" or "n".

Thanks guys,

-Falven

System: Compi
CPU
Intel Core i7 920 @ 3.8 1.35V
Motherboard
Evga X58
Memory
G.Skill 3Gb DDR3 1600 Triple Channel
Graphics Card
Asus EAH4850
Hard Drive
2X OCZ Vertex 30GB Raid 0 + WD VelociRaptor 300GB
Sound Card
SoundBlaster X-FI Extreme Audio
Power Supply
Antec TruePower Trio TP3-650
Case
Modded Antec Three Hundred Black ATX Mid Tower
CPU cooling
XIGMATEK HDT-S1283 + Scythe "ULTRA KAZE"
GPU cooling
Glaciator Fansink
OS
Windows Vista X64/Windows 7
Monitor
Vizio 22" HD 1080P TV

Last edited by falven : 2 Weeks Ago at 05:29 AM
falven is offline   Reply With Quote
Old 2 Weeks Ago   #8 (permalink)
4.0 GHz
 
falven's Avatar
 
intel ati

Join Date: Sep 2008
Location: Florida
Posts: 627

Rep: 23 falven is acknowledged by some
Unique Rep: 20
Trader Rating: 0
Default

bump

System: Compi
CPU
Intel Core i7 920 @ 3.8 1.35V
Motherboard
Evga X58
Memory
G.Skill 3Gb DDR3 1600 Triple Channel
Graphics Card
Asus EAH4850
Hard Drive
2X OCZ Vertex 30GB Raid 0 + WD VelociRaptor 300GB
Sound Card
SoundBlaster X-FI Extreme Audio
Power Supply
Antec TruePower Trio TP3-650
Case
Modded Antec Three Hundred Black ATX Mid Tower
CPU cooling
XIGMATEK HDT-S1283 + Scythe "ULTRA KAZE"
GPU cooling
Glaciator Fansink
OS
Windows Vista X64/Windows 7
Monitor
Vizio 22" HD 1080P TV
falven is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 11:18 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.14997 seconds with 8 queries