Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2007, 03:49 AM
Member
 
Join Date: Jul 2007
Location: Lancaster, CA
Posts: 4
aDrizzle is on a distinguished road
Send a message via AIM to aDrizzle Send a message via MSN to aDrizzle Send a message via Yahoo to aDrizzle
If Statement
I am massively noobing at Java (and programming in general), and am getting very frustrated with it. I have a simple code typed up, and I'm sure my mistake is a simple fix, but there is nothing I can think to do to get my If statement to print.

Code:
import java.util.Scanner; public class Checkpoint3_2 { public static void main(String[] args) { Scanner keyIn = new Scanner(System.in); double rate; int hours; double overTime; String name; double pay; pay = rate * hours; overTime = rate * 1.5; System.out.println("Hello."); System.out.print("What is your name? "); name = keyIn.nextLine(); System.out.println("Hello " + name); System.out.print("Enter rate of pay. "); rate = keyIn.nextDouble(); System.out.print("Enter hours. "); hours = keyIn.nextInt(); if (hours > 40) { pay = overTime * (hours - 40) + (rate * 40); System.out.println("You made " + pay); } else { System.out.println("You made " + pay); System.out.println(":)"); } } }
__________________
I know not what I do, just that I do what it is that I do not know I am doing.

Last edited by JavaBean : 07-08-2007 at 02:04 PM. Reason: Code placed inside [code] tag.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-08-2007, 03:52 AM
Member
 
Join Date: Jul 2007
Location: Lancaster, CA
Posts: 4
aDrizzle is on a distinguished road
Send a message via AIM to aDrizzle Send a message via MSN to aDrizzle Send a message via Yahoo to aDrizzle
Any help would be appreciated. Sorry, I didn't realize it would take away all my indents.
__________________
I know not what I do, just that I do what it is that I do not know I am doing.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-08-2007, 06:16 AM
Member
 
Join Date: Jul 2007
Location: Lancaster, CA
Posts: 4
aDrizzle is on a distinguished road
Send a message via AIM to aDrizzle Send a message via MSN to aDrizzle Send a message via Yahoo to aDrizzle
More specifically, and this just happened on a second program I just wrote:

variable " " might not have been initialized

I assume that may have something to do with it, though, I am unable to find anything on fixing it.
__________________
I know not what I do, just that I do what it is that I do not know I am doing.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-08-2007, 02:07 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Quote:
I assume that may have something to do with it, though, I am unable to find anything on fixing it.
Yes, your mistake is simple and related to that warning message!

Code:
pay = rate * hours; overTime = rate * 1.5;
The place of the above statements is incorrect. If you need to calculate something, you need to get inputs of that calculation first. But you do the calculation first and then get input! And compiler warns you because of that since you did not initialize rate and hours variables.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-08-2007, 09:55 PM
Member
 
Join Date: Jul 2007
Location: Lancaster, CA
Posts: 4
aDrizzle is on a distinguished road
Send a message via AIM to aDrizzle Send a message via MSN to aDrizzle Send a message via Yahoo to aDrizzle
Arrghh, stupid mistake. I distinctly remember not remembering that in class lol. Thank you so much, uber life safer
__________________
I know not what I do, just that I do what it is that I do not know I am doing.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch Statement Help bluegreen7hi New To Java 6 02-06-2008 06:16 AM
goto statement bugger New To Java 2 12-12-2007 04:47 PM
Help with if statement carl New To Java 1 08-06-2007 08:53 AM
there is no return statement gabriel New To Java 1 08-03-2007 07:24 PM
Statement or Prepared Statement ? paty Database 3 08-01-2007 05:45 PM


All times are GMT +3. The time now is 01:53 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org