Team Foundation Server Hosting
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » C# Language » Anyone who is good with JAVA help?
       
Author Reply
Prime b
posted 420 posts
since Dec 12, 2011 
from

Anyone who is good with JAVA help?

  Posted on: 03 Feb 2012       
problem: The user enters seconds the output should be days,hours,minutes,seconds format
So if user enter 86400 seconds it will be 1 day, 0 hours, 0 minutes, 0 seconds.
If User enters 86401 seconds it will be 1 days, 0 hours, 0 minutes, 1 second.
Well this is my code, and it doesn't work..

        Scanner scan = new Scanner(System.in);
        double userInput;
        double secondsInDay = 86400;
        double secondsInhours = 3600;
        double secondsInMinutes = 60;
        double seconds;
      
       
       
        System.out.println("Please enter the seconds to convert to days,hours,minutes,seconds");
        userInput = scan.nextDouble();
       
       
        double answerDay = userInput % secondsInDay;
        double answerHours = answerDay % secondsInhours;
        double answerMinutes = answerHours % secondsInMinutes;
        double answerSeconds = answerMinutes;
       
       
       
//         System.out.println(""+answerDay);
//         System.out.println(""+answerHours);
//         System.out.println(""+answerMinutes);
//         System.out.println(""+answerSeconds);
       
         if(answerDay >= 1)
        {
            System.out.println("Days = "+answerDay);
           
        }
         else if(answerDay == 0)
         {
             System.out.println("Zero days");
         }
        
         if(answerHours >= 1)
         {
             System.out.println("Hours = "+answerHours);
         }
         else if(answerHours == 0)
         {
             System.out.println("Zero hours");
         }
        
         if(answerMinutes >= 1)
        {
            System.out.println("Minutes = "+answerMinutes);
        }
         else if(answerMinutes == 0)
         {
             System.out.println("Zero minutes");
         }
        
         if(answerSeconds >= 1)
        {
            System.out.println("Seconds = "+answerSeconds);
        }
         else if(answerSeconds == 0)
         {
             System.out.println("Zero seconds");
         }

Practice makes it perfect && All science is either computer programming or stamp collecting
Vulpes
posted  5419 posts
since  Feb 28, 2011 
from 

 Re: Anyone who is good with JAVA help?
  Posted on: 03 Feb 2012   Accepted Answer     0  
You need to use int variables here rather than double:

        int userInput;
        int secondsInDay = 86400;
        int secondsInhours = 3600;
        int secondsInMinutes = 60; 

Also, this part of the code:

        double answerDay = userInput % secondsInDay;
        double answerHours = answerDay % secondsInhours;
        double answerMinutes = answerHours % secondsInMinutes;
        double answerSeconds = answerMinutes;

should be:

        int answerDay = userInput / secondsInDay;
        int remainder = userInput % secondsInDay;
        int answerHours = remainder / secondsInhours;
        remainder = remainder % secondsInhours;
        int answerMinutes = remainder / secondsInMinutes;
        int answerSeconds  = remainder % secondsInMinutes;


Prime b
posted  420 posts
since  Dec 12, 2011 
from 

 Re: Anyone who is good with JAVA help?
  Posted on: 03 Feb 2012        0  
yup, it worked, I was thinking about doing something like that but after awhile I switched to C sharp lol...

Practice makes it perfect && All science is either computer programming or stamp collecting
Vulpes
posted  5419 posts
since  Feb 28, 2011 
from 

 Re: Anyone who is good with JAVA help?
  Posted on: 04 Feb 2012        0  
I hope they're not trying to teach you two programming languages at the same time.

Programming is confusing enough when you're starting out and, even though the syntax of Java and C# is fairly similar, trying to learn them both simultaneously is not a good idea, IMO.

It's best to master one language before going on to learn another, otherwise you just end up with a big muddle in your head!
Prime b
posted  420 posts
since  Dec 12, 2011 
from 

 Re: Anyone who is good with JAVA help?
  Posted on: 04 Feb 2012        0  
Well, I am taking 4 classes, 1 is C sharp advanced, 1 is Java , 1 Visual Basic and 1 hardware software support. So I am actually taking 3 programming classes... I am doing not bad in in Java and VB because its pretty similar to C sharp, but C sharp class is giving me some problems..
Practice makes it perfect && All science is either computer programming or stamp collecting
Prime b
posted  420 posts
since  Dec 12, 2011 
from 

 Re: Anyone who is good with JAVA help?
  Posted on: 04 Feb 2012        0  
Btw, do you know JAVA ? So i know for future reference.
And why netbeans has such lame IDE, no intellisense, takes so much more time to type out each variable , reserved words, etc..
Practice makes it perfect && All science is either computer programming or stamp collecting
Vulpes
posted  5419 posts
since  Feb 28, 2011 
from 

 Re: Anyone who is good with JAVA help?
  Posted on: 04 Feb 2012        0  
I have some knowledge of Java but I don't know it as well as I know the .NET languages.

However, we've been getting a lot of questions about Java recently and there's now a dedicated forum category for it. 

Although I don't use it, I thought NetBeans did have intellisense support though I'd be surprised if it was as good as VS.
Sam Hobbs
posted  6490 posts
since  Sep 07, 2009 
from  Los Angeles, California, USA

 Re: Anyone who is good with JAVA help?
  Posted on: 05 Feb 2012        0  
I have heard that Netbeans performance is not good. I know it was slow when I used it with my older system. My current system has 4 cores Netbeans is not much of a problem for me but I do not use it anyway.

Have you tried Eclipse?
Thinking is a feeling; pleasant for some and unpleasant for others.
Prime b
posted  420 posts
since  Dec 12, 2011 
from 

 Re: Anyone who is good with JAVA help?
  Posted on: 07 Feb 2012        0  
Hey Sam! I have heard about eclipse, but I have never used it, also my teacher said no to eclipse.

I just found out you can use ctrl+space and it will display my declared variables , reserved words that you want to use , etc. So its not so bad, before I had to type out everything out....
Practice makes it perfect && All science is either computer programming or stamp collecting
       
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved