0
How to fix this
Convert days to second Code: Import java.util.Scanner; public class program{ Public static void main(String []args){ System.out.println("Enter the days"); Scanner sc= new Scanner (System.in); int days = sc.nextInt(); int dayToHour= days*24; /* 1day=24hour */ int dayToMintue = dayToHour*60; /* 1hour=60min */ int dayToSecond = dayToMintue*60; /* 1min=60 sec */ System.out.println ("converting days to second: " + dayToSecond ); } }
9 Respuestas
+ 2
And the problem in in your print statement u dont need to print any string u just need to print value
+ 1
What that bug?
Is it code coach problem?
Share link code that helps to identify what is the mistake..Meghna Som
Add Expected output with problem description..
0
Do following changes.
Import to import
Public to public
0
"I also tried this ....
Like:
Int second = days*24*60*60;
But it couldn't run ..
It's show me a bugs ..."
Yes, because it's wrong.
Write 'int' instead of 'Int', with lower case 'i'.
Or print direct:
System.out.println(days*24*60*60)
And DO NOT print any additional text like " converting days to.... ". This will produce an error for the CodeCoach. Print ONLY the number of result.
0
Ok ..I will try it...
0
How to fix this
I copy and paste your code and run it. Then I change this lines:
Import java.util.Scanner;
public class program{
Public static void main(String []args)
I changed "Import" to "import" and "Public" to "public".
Then run it. The code works without any problems.
What is the issue?
0
First of all, you don't have to expand the mechanism
int dayToHour= days*24;
/* 1day=24hour */
int dayToMintue = dayToHour*60;
/* 1hour=60min */
int dayToSecond = dayToMintue*60;
/* 1min=60 sec */
like this
Instead of that, you can simply convert days to seconds using
daysToSecond = days * 24 * 60 * 60 ( you have to declare a new variable I'm using int daysToSecond)
fist step - days * 24 means, convert days into 24 hours
if you enter 12 days it multiplies with 24 so then you can get how many hours
second step - days * 24 * 60 means converting the hours into minutes
12 days * 24 = 288 if we multiply 288 hours with 60 we can get 17280 in minutes
third step - days * 24 * 60 * 60 means converting the minutes into seconds
finally, if you multiply 17280 minutes with 60 we can get 1036800 in seconds
which means 12 days = 1036800 seconds
The new code is right below enjoy ;)
public class Main {
public static void main(String[] args) {
System.out.println("Enter the days");
Scanner sc = new Scanner (System.in);
int days = sc.nextInt();
//new code
int daysToSecond = days * 24 * 60 * 60 ;
System.out.println("converting days to second: " + daysToSecond);
}
}
- 1
What is the problem with your code? What is your expected output?
Save code and share link here..
You can write directly like :
days*24*60*60 ,then no need of variables.
- 1
I also tried this ....
Like:
Int second = days*24*60*60;
But it couldn't run ..
It's show me a bugs ...