|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Java problem (need help asap)
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Case Modder
![]() |
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);
}
}
}
}
please don't be like holy crap no comments, I hate commenting until the absolute end.
Last edited by caraboose : 10-16-09 at 11:42 AM |
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||||
|
New to Overclock.net
|
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:
Quote:
Quote:
Last edited by adramalech707 : 10-16-09 at 02:39 PM |
|||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|