Converting hours:minutes into minutes
I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);
}
}
java debugging
add a comment |
I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);
}
}
java debugging
3
Multiply hours by 60, add minutes.
– Andy Turner
Oct 26 '15 at 16:09
3
Removehours/hourConv+minutes/minConv
and addhours*hourConv+minutes
– Rakesh
Oct 26 '15 at 16:10
If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).
– Andy Turner
Oct 26 '15 at 16:11
add a comment |
I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);
}
}
java debugging
I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);
}
}
java debugging
java debugging
edited Oct 26 '15 at 16:18
Perdomoff
8212723
8212723
asked Oct 26 '15 at 16:06
lxtrxilxtrxi
40212
40212
3
Multiply hours by 60, add minutes.
– Andy Turner
Oct 26 '15 at 16:09
3
Removehours/hourConv+minutes/minConv
and addhours*hourConv+minutes
– Rakesh
Oct 26 '15 at 16:10
If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).
– Andy Turner
Oct 26 '15 at 16:11
add a comment |
3
Multiply hours by 60, add minutes.
– Andy Turner
Oct 26 '15 at 16:09
3
Removehours/hourConv+minutes/minConv
and addhours*hourConv+minutes
– Rakesh
Oct 26 '15 at 16:10
If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).
– Andy Turner
Oct 26 '15 at 16:11
3
3
Multiply hours by 60, add minutes.
– Andy Turner
Oct 26 '15 at 16:09
Multiply hours by 60, add minutes.
– Andy Turner
Oct 26 '15 at 16:09
3
3
Remove
hours/hourConv+minutes/minConv
and add hours*hourConv+minutes
– Rakesh
Oct 26 '15 at 16:10
Remove
hours/hourConv+minutes/minConv
and add hours*hourConv+minutes
– Rakesh
Oct 26 '15 at 16:10
If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).
– Andy Turner
Oct 26 '15 at 16:11
If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).
– Andy Turner
Oct 26 '15 at 16:11
add a comment |
3 Answers
3
active
oldest
votes
Fixed: Multiply hours by 60 then add your minutes.
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+((hours * 60)+minutes));
}
}
add a comment |
If you want the result of 02:20 to 140 then you have just have to do this:
System.out.println("Total minutes: "+(hours*hourConv+minutes));
add a comment |
you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .
1
Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.
– APH
Oct 26 '15 at 16:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33350373%2fconverting-hoursminutes-into-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Fixed: Multiply hours by 60 then add your minutes.
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+((hours * 60)+minutes));
}
}
add a comment |
Fixed: Multiply hours by 60 then add your minutes.
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+((hours * 60)+minutes));
}
}
add a comment |
Fixed: Multiply hours by 60 then add your minutes.
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+((hours * 60)+minutes));
}
}
Fixed: Multiply hours by 60 then add your minutes.
import java.util.Scanner;
public class TimeAssignment {
public static void main(String args){
Scanner input = new Scanner(System.in);
final double minConv = 0.0166667;
final double hourConv = 60;
int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();
int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();
System.out.println("Total minutes: "+((hours * 60)+minutes));
}
}
edited Nov 20 '18 at 21:14
answered Oct 26 '15 at 16:15
PerdomoffPerdomoff
8212723
8212723
add a comment |
add a comment |
If you want the result of 02:20 to 140 then you have just have to do this:
System.out.println("Total minutes: "+(hours*hourConv+minutes));
add a comment |
If you want the result of 02:20 to 140 then you have just have to do this:
System.out.println("Total minutes: "+(hours*hourConv+minutes));
add a comment |
If you want the result of 02:20 to 140 then you have just have to do this:
System.out.println("Total minutes: "+(hours*hourConv+minutes));
If you want the result of 02:20 to 140 then you have just have to do this:
System.out.println("Total minutes: "+(hours*hourConv+minutes));
edited Oct 26 '15 at 16:21
answered Oct 26 '15 at 16:11
ShivamShivam
479619
479619
add a comment |
add a comment |
you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .
1
Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.
– APH
Oct 26 '15 at 16:33
add a comment |
you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .
1
Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.
– APH
Oct 26 '15 at 16:33
add a comment |
you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .
you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .
answered Oct 26 '15 at 16:20
dinesh kumardinesh kumar
143
143
1
Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.
– APH
Oct 26 '15 at 16:33
add a comment |
1
Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.
– APH
Oct 26 '15 at 16:33
1
1
Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.
– APH
Oct 26 '15 at 16:33
Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.
– APH
Oct 26 '15 at 16:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33350373%2fconverting-hoursminutes-into-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Multiply hours by 60, add minutes.
– Andy Turner
Oct 26 '15 at 16:09
3
Remove
hours/hourConv+minutes/minConv
and addhours*hourConv+minutes
– Rakesh
Oct 26 '15 at 16:10
If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).
– Andy Turner
Oct 26 '15 at 16:11