The Artima Developer Community
Sponsored Link

Java Answers Forum
projectDue = HELP;

1 reply on 1 page. Most recent reply: May 5, 2003 6:05 AM by Erik Price

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
brandon

Posts: 2
Nickname: cheezzer
Registered: May, 2003

projectDue = HELP; Posted: May 4, 2003 6:10 PM
Reply to this message Reply
Advertisement
Help, I have a small project due on Wedensday, and I'm not all together correct on some of it.First,I need to use variables and calculations to convert 22406 feet into miles,yards and feet. There are 3 feet in a yard, 1760 yards in a mile. I know the answer should be 4 miles,428 yards and 2 feet.I also need to plug other values different than 22406 feet, in order to test the program. Here's what i got so far

public class Convert1

public static void main(String[] args)
{
int feet = 12;
int yard = 3 feet;
int mile = 1760 yard;

System.out.println("The total distanc is " " + "" + ");

}
}
} Could someone critique this Please!!


Erik Price

Posts: 39
Nickname: erikprice
Registered: Mar, 2003

Re: projectDue = HELP; Posted: May 5, 2003 6:05 AM
Reply to this message Reply
> Could someone critique this Please!!
public class Convert1 {
 
  public static void main(String[] args) {
    int feet = 12;
    int yard = 3 feet;
    int mile = 1760 yard;
 
    System.out.println("The total distanc is " " + "" + ");
 
  }
}

Well, you've got a class with a main method, so you can execute this class. But it doesn't do anything. You've declared some integer variables and initialized them to values, which is nice, but the syntax isn't really correct -- you can't put "feet" or "yard" after an integer in the code, because the compiler has no idea what you mean by this. Finally, you have a System.out.println statement which also won't compile, because your quotes don't appear to be balanced.

I'll give you three hints:

1. You can make a variable assignment using another variable's value, like this:
int quart = 32;
int gallon = 4 * quart;

2. The System.out.println method takes a single argument. You can build up a single argument by adding primitives together, or by concatenating String objects together, or by combining both techniques. Either way, you need to end up with a single value that becomes the argument to println.

3. Instead of hardcoding a value into your source code, you can pass it into the program at runtime (after you've compiled it, when you're executing it) as an argument to your command in the shell/DOS prompt. But you will need to refer to this argument somehow from within your program. Big hint: there's a reason that the String[] argument to the main method is often called "args".


I hope these pointers will help show the way, or at least provide you with some keywords that you can use to research the solutions. Good luck.

Flat View: This topic has 1 reply on 1 page
Topic: setLocation() Previous Topic   Next Topic Topic: What the command for OR ... ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use