Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 ----Time---
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xX_MayDay_Xx




PostPosted: Tue Feb 28, 2006 8:08 am   Post subject: (No subject)

ok....well that does give me the value, but that dosnt solve my problem

im trying to get the user to input a capitol letter..

"Plz enter a capitol letter"

and then it gives the user the value of it

"You enter 'A'--the value of A=1"

but it most be able to do this for all numbers

"You entered 'Z'--the value of Z=26"
Sponsor
Sponsor
Sponsor
sponsor
xX_MayDay_Xx




PostPosted: Tue Feb 28, 2006 8:20 am   Post subject: (No subject)

like this is what i have so far and it wont work

code:
public class Alphabit
{
        public static void main (String[]args)
        {
                int A=('A'-'A'+1);
                int B=('B'-'A'+1);
                int C=('C'-'A'+1);
                int D=('D'-'A'+1);
                int E=('E'-'A'+1);
                int F=('F'-'A'+1);
                int G=('G'-'A'+1);
                int H=('H'-'A'+1);
                int I=('I'-'A'+1);
                int J=('J'-'A'+1);
                int K=('K'-'A'+1);
                int L=('L'-'A'+1);
                int M=('M'-'A'+1);
                int N=('N'-'A'+1);
                int O=('O'-'A'+1);
                int P=('P'-'A'+1);
                int Q=('Q'-'A'+1);
                int R=('R'-'A'+1);
                int S=('S'-'A'+1);
                int T=('T'-'A'+1);
                int U=('U'-'A'+1);
                int V=('V'-'A'+1);
                int W=('W'-'A'+1);
                int X=('X'-'A'+1);
                int Y=('Y'-'A'+1);
                int Z=('Z'-'A'+1);
                System.out.println("please input a Capitol Letter");
                B=In.getInt();
                System.out.println("wow...its working"+(B));
        }
}
Andy




PostPosted: Tue Feb 28, 2006 8:43 am   Post subject: (No subject)

wow.. that is really really sad...

ask the user to input a character, and store it in a variable, then take that variable and subtract 'A' then add 1
xX_MayDay_Xx




PostPosted: Tue Feb 28, 2006 9:14 am   Post subject: (No subject)

ok...well that didn't work as well...but this did



code:
public class Alpha
{
        public static void main (String[]args)
        {
                char letter;
                int value;

                System.out.println("Plz enter a capitol letter");
                letter=In.getChar();
                value = (int)(letter);
                System.out.println("the value of that letter is");
                System.out.println("the value of that letter is "+value - 64);
        }
}
Andy




PostPosted: Tue Feb 28, 2006 9:33 am   Post subject: (No subject)

that's essentially what i told you to do.. 'A' == 65, so basicly by subtracting that and adding 1 you're subtracting 64.. w.e as long as you got it
xX_MayDay_Xx




PostPosted: Thu Mar 02, 2006 8:24 am   Post subject: (No subject)

um ok...this program works for the most part, im just having trouble finalizing it, The math is correct, i tripled checked it on paper...but for some reason it just wont calculate properly...

code:

public class Easter
{
        public static void main (String[]args)
        {
                int p,q,r,s,t,u,m,d,y;
                System.out.println("Welcome to the Easter Calculator");
                System.out.println("Enter which year you would like "
                                                                                + "to find Easter on");
                y = In.getInt();
                p = (y/100);
                q = (y-19)*(y/19);
                r = ((p-17)/25);
                s = (p-(p/4))-((p-r)/3)+(19*q)+(15);
                s = (s-30)*(s/30);
                s = (s-(s/28))*(1-(s/28)*(29/(s+1))*((21-q)/11));
                t = (y+(y/4)+s+2-p+(p/4));
                t = (t-7)*(t/7);
                u = (s-t);
                m = 3+((u+40)/44);
                d = (u+28-31*(m/4));
                System.out.println("easter will be on");
            System.out.println("Month "+m);
                System.out.println("day "+d);
                System.out.println("in the year "+y);
        }
}
MysticVegeta




PostPosted: Thu Mar 02, 2006 2:38 pm   Post subject: (No subject)

What the hell? I cant even understand a thing going on with that code. Messy var names, messy calcs.. but I do see one thing, when you are dividing something you are not casting it.

Anyways, why not just look for any years easter and then use loops to solve the problem. Ex: if you know that on day x easter falls, in 2006, and user enters 2007 or anything, just use loops..
xX_MayDay_Xx




PostPosted: Fri Mar 03, 2006 8:17 am   Post subject: (No subject)

um....i know im not the best a programing...in fact i down right suck...but your method is completly messed up, if i used "If" statments and loop's..the code would be ten times as long as it is now...this has to be able to calulate easter in any year..from the year 200 to 567893043974987343987263498........yeah so pretty much your code would run forever...and second, i already fiqured out the problem, it was that i had to many brakets that screwed up 'BEDMAS'
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Fri Mar 03, 2006 3:42 pm   Post subject: (No subject)

I guarantee you, the code wont be 10 times longer, not even 2 times longer, a loop is made to "save" code length not increase it by 10X, I suggested loops because anyone looking at your code would simply go "What is this mess?" Whereas if you actually count the # of days and then mod(ulos) by 7, you will get after how many days / before how many days, will the year appear.

But if you want to stick to the confusing method, you should go right ahead. Because quite frankly if a teacher will look at this:

code:
      p = (y/100);
      q = (y-19)*(y/19);
      r = ((p-17)/25);
      s = (p-(p/4))-((p-r)/3)+(19*q)+(15);
      s = (s-30)*(s/30);
      s = (s-(s/28))*(1-(s/28)*(29/(s+1))*((21-q)/11));
      t = (y+(y/4)+s+2-p+(p/4));
      t = (t-7)*(t/7);
      u = (s-t);
      m = 3+((u+40)/44);


I am sure a mark of 0 for organization will be given.
[Gandalf]




PostPosted: Sat Mar 04, 2006 9:05 am   Post subject: (No subject)

xX_MayDay_Xx wrote:
this has to be able to calulate easter in any year..from the year 200 to 567893043974987343987263498.

Then you'd better be changing your type from 'int' to something more appropriate. As it stands, you're limited to the year 2147483647. Good luck!
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 40 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: