Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

java help for beginners

Name: Anonymous 2009-02-08 18:18

Compute the remainder of seconds entered by the user by the number of seconds
in an hour (SECONDS_X_MINUTE).


import java.util.Scanner;

public class Time {

    public static final int SECONDS_X_HOUR = 3600;
    public static final int SECONDS_X_MINUTE = 60;
    public static final int AM_PERIOD = 43199;
    public static void main(String[] args) {
   
        int timeInSeconds;
        int timeInHours;
        int remainderHours;
        int timeInMinutes;
        int standardTimeInHours;
       
        Scanner keyboard = new Scanner(System.in);
        System.out.println ("Please Enter Time in Seconds :\t");
        timeInSeconds = keyboard.nextInt();
        timeInHours = timeInSeconds/SECONDS_X_HOUR;   
        remainderHours = timeInHours&SECONDS_X_HOUR;
        timeInMinutes = remainderHours * SECONDS_X_MINUTE;
       
       
        System.out.println (timeInSeconds + " " + timeInHours + " " + remainderHours + " " +timeInMinutes);
        System.out.println ("Please enter the time in seconds: " + timeInSeconds);
        System.out.println ("Standard Format: " + (int)timeInHours + "h. " + timeInMinutes + "m. " + timeInSeconds + "s.");
        System.out.println ("AM/PM Format: " + timeInHours + "h. " + timeInMinutes + "m. " + timeInSeconds + "s.");


    }

}

Name: Anonymous 2009-02-08 18:19

basically i am trying to figure out how to get the remainder from the timeInHours calculation

Name: Anonymous 2009-02-08 18:22

I think I just threw up a little

Name: Anonymous 2009-02-08 18:24

I think I just threw up a lot

Name: Anonymous 2009-02-08 18:26

ok its an int so something like 26/3 is going to come up as 8 i realize but if you could me out that would be great

Name: Anonymous 2009-02-08 18:30

JAVA HAS A FUCKING MODULUS OPERATOR FOR FUCKS SAKE USE THAT

Name: Anonymous 2009-02-08 18:36

oh fuck yeah i meant % instead of & but im still not getting the remainder like i want

Name: Anonymous 2009-02-08 18:40

DON'T HELP HIM!!!

Name: Anonymous 2009-02-08 18:44

god. thanks.

Name: Anonymous 2009-02-08 18:47

>>8 I wasn't going to help him till you did that, now i will

remainderHours = timeInHours%SECONDS_X_HOUR;
You're taking modulus of timeInHours, so the answer you get will always be the same as timeInHours

Now if you take timeInSeconds%SECONDS_X_HOUR you will get the number of seconds remaining.

i.e. 4.30 am =  16200s,
     16200/3600 = 4h
     16200%3600 = 1800s

Name: Anonymous 2009-02-08 18:48

/prog/ - /pr/

Name: Anonymous 2009-02-08 18:50

THIS THREAD IS NOW ABOUT HOW JAVA SUCKS BALLS!!!!!!!!

Name: Anonymous 2009-02-08 19:00

>>10
thanks for not being a prick

Name: Anonymous 2009-02-08 19:08

>>13
no thanks for not reading SICP

Name: Anonymous 2009-02-08 19:30

1. Divide the seconds entered by the user by the number of seconds in an hour
(SECONDS_X_HOUR), the result will be the hours in standard time.

5. The number of hours in AM/PM format is the remainder of dividing the hours in
standard time computed in (1) by 12.

again i think this might be a logic error on my part.

is this this what the problem is asking? if so my output is messed up.

int AmPmTimeInHours = (timeInSeconds%SECONDS_X_HOUR)/12;

Name: Anonymous 2009-02-08 19:34

i figured it out
int AmPmTimeInHours = timeInHours%12; its that right?

Name: Anonymous 2009-02-08 20:21

Do your own homework.  Nothing you are being asked to do is hard, the majority of your errors are because you aren't even thinking about what you want to do, you are just writing statements.  This isn't a "We'll write your programs" board.

Name: Anonymous 2009-02-08 21:12

will someone write a program doing the pythageron law for me plz?

Name: Anonymous 2009-02-08 21:49

>>18
I will, along with haxing your anus.

Name: Anonymous 2009-02-08 23:14

>>18
Fuck. IHBT

Name: Anonymous 2009-02-09 6:06

We have been trolled constantly.

Name: Anonymous 2009-02-09 8:14

>>18
int main(int argc,char**argv){
 int a,b,c;
 if(argc<2)return 1;
 a=atoi(argv[1])
 b=atoi(argv[2])
 c=sqrt(a*a+b*b);
 printf("%d",c);
}

Name: Anonymous 2009-02-09 8:32

pyth a b = sqrt $ a**2 + b**2

Name: Anonymous 2009-02-09 12:57

>>22
int

Horrible!

Name: Anonymous 2009-02-09 13:41

>>24
Not really -- int arithmetic is faster.

Name: Anonymous 2009-02-09 14:02

>>23
pyth a b = sqrt . foldl (+) 0 $ map (**2) [a, b]

Name: Anonymous 2009-02-09 15:33

>>26
I do not use folds because I am GvR.

Name: Anonymous 2009-02-09 15:43

I do not use folds because I am "GRUNNER"

Name: Anonymous 2009-02-09 15:44

>>23,26
pyth a b = sqrt . sum $ map (**2) [a, b]
or you could use a better language:
: pyth ( a b -- c ) [ sq ] bi@ + sqrt ;

and then there's this bullshit:
sub pyth($$){sqrt sum map{$_**2}@_}

>>27
GvR would probably do something like this:
(a*a+b*b)oh god how did i get here im not good with computer

Name: Anonymous 2009-02-09 16:37

>>25
But you can't sqrt an int.

Name: Anonymous 2009-02-09 16:41

>>30
But you can sqrt a fish

Name: Anonymous 2009-02-09 17:29

>>29
sub pyth($$){sqrt sum map{$_**2}@_}

Prototypes considered harmful.

Name: Anonymous 2009-02-09 18:37

>>30
int isqrt(n){
 /* calculates integer square root.    *
  * if n is less than zero, calculates *
  * integer square root divided by i.  */
  int r = 0, i = 1;
  if(0 > n) n = -n;
  for(i = i << ((sizeof(int) * CHAR_BIT - (0 > ~i ? 2 : 1)) / 2) * 2; i; i >>=2)
    if(n >= (i | r)){
      n -= i | r;
      r = r >> 1 | i;
    }else r >>= 1;
  return r;
}

Name: Anonymous 2009-02-09 19:12

>>25,33
int i = sqrt(2);
float f = sqrt(2);
assert( (float) i == f);

Name: Anonymous 2009-02-09 19:28

>>34
int i = 2;
assert(sqrt(i) == sqrt(2));

Name: Anonymous 2009-02-09 22:10

>>34-35
Actually, i = sqrt(-1)

Name: Anonymous 2009-02-09 22:12

>>36
no, i = sqrt(-1)

Name: Anonymous 2011-02-03 2:39

Name: Anonymous 2013-01-19 23:14

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List