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 > Application Programming

Reply
 
LinkBack Thread Tools
Old 10-16-09   #1 (permalink)
Case Modder
 
caraboose's Avatar
 
intel nvidia

Join Date: Aug 2008
Location: CYBW
Posts: 2,290
Blog Entries: 1

Rep: 151 caraboose is acknowledged by manycaraboose is acknowledged by many
Unique Rep: 127
Hardware Reviews: 1
Trader Rating: 11
Default Java problem (need help asap)

So I'm doing an assignment and my teacher said we have all the resources available to us and I think I've gotten most of the coding done but I just cant figure out part of it
I'll put in bold and biggere text what I can't figure out.
Code:
import java.util.Scanner;
public class Assignment {
	public static void main(String[] args){
		// Problem: Your calculator kicked the bucket
		System.out.println("How many numbers do you want calculated?");
		Scanner A = new Scanner(System.in);
		int B = A.nextInt();
		
		System.out.println("Do you want to add or subtract?");
		Scanner D = new Scanner (System.in);
		String s1 = "subtract";
		if (D == s1);
		String E = D.next();
		if (E.equalsIgnoreCase ("+"))
		{
			for (int C = 0; C < B; C++);
			{
				System.out.println("Enter the numbers");
				double F = D.nextDouble();
				System.out.print(D);
			}
		}
		else 
			if (E.equalsIgnoreCase ("-"));
		{
			for (int C = 0; C < B; C++);
			{
				System.out.println("Enter the numbers");
				double G = D.nextDouble();
				System.out.print(D);
			}
		}		
	}
}
I'm trying to get it so that if D is typed in as subtract that it'll know to do subtraction, but I can't figure it out please don't be like holy crap no comments, I hate commenting until the absolute end.
__________________
Canadian OCN Club
STARGATE
We Are Gr33n Machine

Quote:
Originally Posted by Havegooda View Post
Two things will survive a nuclear blast: Cockroaches and AGP.
09-12-09


System: C-YEGH
CPU
i7 920 D0 @ 4.2GHz
Motherboard
Evga X58 Classified
Memory
Mushkin Redline XP3-12800
Graphics Card
2 GTX280, 8800GT
Hard Drive
500, 320, 250, 250 GB Seagate Barracudas
Sound Card
onboard
Power Supply
1000HX
Case
HAF 932 for now, Diamaond Dragon [coming]
CPU cooling
Apogee GTZ + 2 MCR220
GPU cooling
stock
OS
Vista Ultimate X64
Monitor
3 22" LG monitors

Last edited by caraboose : 10-16-09 at 11:42 AM
caraboose is online now caraboose's Gallery   Reply With Quote
Old 10-16-09   #2 (permalink)
New to Overclock.net
 
adramalech707's Avatar
 
intel nvidia

Join Date: Feb 2008
Posts: 219

Rep: 5 adramalech707 Unknown
Unique Rep: 5
Folding Team Rank: 691
Trader Rating: 0
Default

you have to use string1.equal(string2); not = or == that is used for true false in integers from what i understand about string comparison what you need to do is go here and read about the string comparison...

http://leepoint.net/notes-java/data/...omparison.html

and here is the documentation on equals()...

http://java.sun.com/j2se/1.4.2/docs/...a.lang.Object)


so it should be if(D.equals(S1)){ String E = D.next(); }

another thing is label all your variables at the beginning so you can reuse them....because using String E in a if statement you won't be able to use it outside of the if because it is not substantiated correctly remember variable scope...
__________________
x2 4600+ @2.6ghz

x2 6400+ @ 3.5ghz

Quote:
When you say "I wrote a program that crashed Windows", people just stare at you blankly and say "Hey, I got those with the system, *for free*"
-Linus Torvalds
Quote:
"How should I know if it works? That's what beta testers are for. I only coded it."
-Linus Torvalds
Quote:
Be warned that typing \fBkillall \fIname\fP may not have the desired effect on non-Linux systems, especially when done by a privileged user.
-killall man page

System: Intel build
CPU
i7 860 @ 2.8ghz
Motherboard
gigabyte p55-ud6
Memory
dominator gt CMG4GX3M2A1600C7
Graphics Card
bfg 9600gt oc2
Hard Drive
wd caviar 500gb
Power Supply
750watt toughpower
Case
antec 900
CPU cooling
coolermaster hyper tx3
GPU cooling
stock
OS
windows 7/ gentoo 64bit
Monitor
samsung 2243swx

Last edited by adramalech707 : 10-16-09 at 02:39 PM
adramalech707 is offline I fold for Overclock.net   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 06:27 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.13084 seconds with 8 queries