5 Replies - 575 Views - Last Post: 14 May 2009 - 02:47 AM Rate Topic: -----

#1 vwyodapink  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 141
  • Joined: 12-May 09

Why wont the minutes display

Post icon  Posted 13 May 2009 - 10:10 AM

I am trying to write a prog that converts minutes in to hours and minutes. I am getting the decimal displayed but it is not taking the remainder of minutes and displaying them. I also cant get it to say " X amount of hours & X amount of minutes worked" Hope this makes sense.

import java.util.Scanner;
public class Time
{
	public static void main(String[] args)
	{
		int minutes;
		double hours;
		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Enter the amount of minutes you have worked");
	   minutes = keyBoard.nextInt();
		hours = (minutes / 60);
		System.out.println("Total hours " + " & minutes " + hours);
		}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Why wont the minutes display

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Why wont the minutes display

Posted 13 May 2009 - 10:17 AM

You don't have the minutes variable in there:

System.out.println("Total hours " + hours +  " & minutes " + minutes);


Was This Post Helpful? 1
  • +
  • -

#3 vwyodapink  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 141
  • Joined: 12-May 09

Re: Why wont the minutes display

Posted 13 May 2009 - 10:28 AM

View PostKYA, on 13 May, 2009 - 09:17 AM, said:

You don't have the minutes variable in there:

System.out.println("Total hours " + hours +  " & minutes " + minutes);




By doing it that way when it displays I just get the minute amount I entered to convert not the remainder of minutes from the calculation.
Was This Post Helpful? 0
  • +
  • -

#4 rolst002  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 13-May 09

Re: Why wont the minutes display

Posted 13 May 2009 - 10:52 AM

System.out.println("Total hours " + hours + " & minutes " + minutes % 60);
Was This Post Helpful? 1
  • +
  • -

#5 vwyodapink  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 141
  • Joined: 12-May 09

Re: Why wont the minutes display

Posted 13 May 2009 - 11:07 AM

View Postrolst002, on 13 May, 2009 - 09:52 AM, said:

System.out.println("Total hours " + hours + " & minutes " + minutes % 60);


Thanks that worked.. I keep forgetting what I can use and what I cant use. I really appriciate the help everyone is offering. Didnt think doing Java through an accelerated class would be so rough for me. SO kudos to all!!!! Things are slowly clicking in with me
Was This Post Helpful? 0
  • +
  • -

#6 ZoneOUT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-May 09

Re: Why wont the minutes display

Posted 14 May 2009 - 02:47 AM

Just in case you didn't know, the % sign is called the modulas and it will return the remainder of any division.

x = 26 % 5 will make x equal to 1
think long division when you used to put the 5 r1 instead of calculating a decimal.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1