Hi can anyone see anything glaringly wrong in this code its only a few line

class test
public static void main(String []args)
public void display()
     int limit=5;
     int total=0;
     for (int i = 0; i<limit; i++)
          System.out.println(i*i+i);
          total+=i;
     System.out.println(total);

see after running this code
public class test
     public static void display()
     int limit=5;
     int total=0;
     for (int i = 0; i<limit; i++)
          System.out.println(i*i+i);
          total+=i;
               System.out.println(total);
                    public static void main(String []args)
                              display();
I get this output
0
2
6
12
20
10
but when i work it out in my mind i get this
2
12
and then i stop because i wonder why i didnt get the 0 and why i missed the 6
can anyone work out what im doing wrong
thanks

Similar Messages

  • Can anybody see what is wrong with this SQL statement?

    Hey guys, just a quick question. Can anybody tell me what is wrong with this line of SQL? I keep getting a syntax error message. I've been trying for ages and I can't see any problem at all!"
    {code}prepStat = connection.prepareStatement("INSERT INTO WeatherHistory (Date, Location, Overview, Temperature, WindDirection, WindSpeed, Pressure) VALUES ('"+date+"','"+location+"','"+temp+"','"+windDir+"','"+windSpd+"','"+pressure+"')");{code}
    All the field names and variables definitely exist so I can't see what the problem is!

    DHD wrote:
    Thanks for the replies.
    I've matched the correct number of column names and variables, but still no luck.
    And how exactly am I misusing Prepared Statements here?As noted above, not according to the code you posted. I didn't just pluck something out of my @ss and throw it out there. There was a reason behind what I said. And, if you mean you changed it, and you still got an exception, then post that exception (completely), and your new code, which is, hopefully, using PreparedStatement, (properly).

  • Can someone see what is wrong with this?  Im stumped

       public class Card {
         int suit;
         int value;
         static int isStraight = 0;
         static int isFlush = 0;
         static int handCounter = 0;
         static int cardCounter = 0;
         boolean inUse = false;
         public int getSuit() {
              return suit;
         public void setSuit(int suit) {
              this.suit = suit;
         public int getValue() {
              return value;
         public void setValue(int value) {
              this.value = value;
         public boolean isInUse() {
              return inUse;
         public void setInUse(boolean inUse) {
              this.inUse = inUse;
        public static int checkPairs(int[] handValues){
             for (int x = 0; x<5; x++ ){
                  for (int y = 0; y<5; y++ ){
                       if(handValues[x]==handValues[y]){
                            cardCounter ++;
                  handCounter = handCounter + (cardCounter - 1);
                   cardCounter = 0;
             System.out.println(handCounter);
             return handCounter;
        public static int checkStraight(int[] handValues){
                  if(handValues[0] == (handValues[1]-1)){
                       if (handValues[1] == (handValues[2]-1)){
                            if (handValues[2] == (handValues[3]-1)){
                                 if (handValues[3] == (handValues[4]-1)){
                                      ///System.out.println("straight");
                                          isStraight = 1;
                                      if (handValues[4] == 12){
                                            isStraight = 2;
                  return isStraight;
        public static int checkFlush(Card[]inputHand){
             if (inputHand[0].suit == inputHand[1].suit){
                  if (inputHand[1].suit == inputHand[2].suit){
                       if (inputHand[2].suit == inputHand[3].suit){
                            if (inputHand[3].suit == inputHand[4].suit){
                                 isFlush = 1;
             return isFlush;
    //handCheckerApp ,
    import tcdIO.*;
    public class handCheckerApp {
         ///these string arrays just hold the names of the values
         static String[] suitsArray = {"hearts" , "spades" , "diamonds" , "clubs" };
         static String[] valuesArray = {"two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" , "ten" , "jack" , "queen" , "king" ,"ace" };
         public static void main (String arguments []) {
              Terminal terminal = new Terminal();
              Card[] inputHand = new Card[5];
              Card[] deck = new Card[52];
              Card currentCard = new Card();
              for(int number = 0 ; number <= 12 ; number++){
                   deck[number]= new Card();
                   deck[number].suit = 0;
                   deck[number].value = number;
              for(int number = 13 ; number <= 25 ; number++){
                   deck[number]= new Card();
                   deck[number].suit = 1;
                   deck[number].value = (number - 13);
              for(int number = 26 ; number <= 38 ; number++){
                   deck[number]= new Card();
                   deck[number].suit = 2;
                   deck[number].value = (number - 26);
              for(int number = 39 ; number <= 51 ; number++){
                   deck[number]= new Card();
                   deck[number].suit = 3;
                   deck[number].value = (number - 39);
              terminal.println("Poker Hand Checker");
              terminal.println("~~~~~~~~~~~~~~~~~~");
              terminal.println("Suits key:..Hearts = 1");
              terminal.println("...................Spades = 2");
              terminal.println("...................Diamonds = 3");
              terminal.println("...................Clubs = 4");
              terminal.println(".............................");
              terminal.println("Values key:.Twos = 2");
              terminal.println("......................Threes = 3");
              terminal.println("......................Fours = 4");
              terminal.println("......................Fives = 5");
              terminal.println("......................Sixes = 6");
              terminal.println("......................Sevens = 7");
              terminal.println("......................Eights = 8");
              terminal.println("......................Nines = 9");
              terminal.println("......................Tens = 10");
              terminal.println("......................Jacks = 11");
              terminal.println("......................Queens = 12");
              terminal.println("......................Kings = 13");
              terminal.println("......................Aces = 14");
          ///this block of code marks cards in the deck as in use and adds them to the hand 
          for(int i = 0; i < 5; i++){///for1
              currentCard.value = (terminal.readInt("please enter card " + (i+1) + " value: " )-2);
              currentCard.suit = (terminal.readInt("please enter card " + (i+1) + " suit: " )-1);
              for (int x = 0; x< 52; x++){///for2
                   if (deck[x].value == currentCard.value){///if1
                        if (deck[x].suit == currentCard.suit){///if2
                            if (deck[x].inUse == true){///elseif1
                                 terminal.println("you chose that card already");
                                 i--;
                            }///if3
                            else if(deck[x].inUse == false){///if3
                                 deck[x].inUse = true;
                                 inputHand[i] = deck[x];
                                 terminal.println("this card is the " + valuesArray[(inputHand.value)] + " of " + suitsArray[(inputHand[i].suit )]);
                        }///elseif1
                   }///if2
              }///if1
         }///for2
         }///for1     
         int handValues[] = {inputHand[0].value, inputHand[1].value, inputHand[2].value, inputHand[3].value, inputHand[4].value};
         java.util.Arrays.sort(handValues);     
         ///this method checks for pairs, two pairs, three of a kind, full house & four of a kind
         Card.checkPairs(handValues);
         if (Card.handCounter == 2) {
                   terminal.println("You have a pair");
              if (Card.handCounter == 4) {
                   terminal.println("You have two pair");
              if (Card.handCounter == 6) {
                   terminal.println("You three of a kind");
              if (Card.handCounter == 8) {
                   terminal.println("You have a full house");
              if (Card.handCounter == 12) {
                   terminal.println("You have four of a kind");
              } else {
                   terminal.println("");
              Card.checkStraight(handValues);
              Card.checkFlush(inputHand);
                   if (Card.isStraight == 1 && Card.isFlush == 0){
                        terminal.println("You have a straight");
                   if (Card.isStraight == 1 && Card.isFlush == 1){
                        terminal.println("You have a straight flush");
                   if (Card.isStraight == 2 && Card.isFlush == 0){
                        terminal.println("You have a royal straight");
                   if (Card.isStraight == 2 && Card.isFlush == 1){
                        terminal.println("You have a royal straight flush");
                   if (Card.isStraight == 0 && Card.isFlush == 1){
                        terminal.println("You have a flush");
                   if (Card.isStraight == 0 && Card.isFlush == 0){
                        terminal.println("");
    Okay it's not recognising deck.inUse....i can't see why.
    Can someone possibly point out some suggestions. Thanks, much appreciated.

    > if (deck[x].inUse == true){///elseif1
    >
    it's giving me an error on this If else statement...
    sorry ....
    How about going the extra mile and actually posting the error message you receive rather than expecting everyone to guess? The more pertinent information you can provide, the easier it is to answer your question. And you want your question answered easily and quickly, right?
    ~

  • Over the years I have backed up my ifoto albums on discs. Now with the new ifoto in 10.7.5 I can't see the fotos from five year old discs--only a dotted line outline of the fotos, all black and white; no images. What gives? and how can I view them?

    Over the years I have backed up my ifoto albums on discs. Now with the new ifoto I cannot see any fotos when I insert the 'old' discs, just dotted lines around where the foto should be. How can I view the fotos? They were backed up for security, but now they are so secure I can't view them! Help!

    If you're running iPhoto 9.5 you'll need to follow these directions in order to view disk created by previous versions of iPhoto: 
    1 - Copy the library from the disk to the Desktop.
    2 - Double click on the iPhoto Library Upgrader tool to launch it  and select the library on the desktop to convert.
    3 - Once that is done you can open it with iPhoto 9.5.
    From iPhoto 9.5: Using iPhoto libraries saved to CD or DVD
    OT

  • Can anyone see what is wrong here?

    Here we go.....I am working on an assessment at Uni. I have written the following code. It compiles with no errors.....it starts to run (ie it asks for the 2 file names to impliment the equi-join) but it doesnt seem to pass a return value. The program produces no output!!! HELP!!!
    private static Map equiJoin(Map relation1, Map relation2)
              Map resultRelation = new TreeMap();
              Iterator keys1Iterator = relation1.keySet().iterator();
              Iterator values1Iterator = relation1.values().iterator();
              Iterator keys2Iterator = relation2.keySet().iterator();
              Iterator values2Iterator = relation2.values().iterator();
              while (keys1Iterator.hasNext())     //loop through relation1
                   String primaryKey1 = (String)keys1Iterator.next();
                   String foreignKey1 = (String)values1Iterator.next();
                   while (keys2Iterator.hasNext())//loop through realtion2
                   String primaryKey2 = (String)keys2Iterator.next();
                   String foreignKey2 = (String)values2Iterator.next();
                   if (foreignKey1 == primaryKey2)
                   resultRelation.put(primaryKey1, primaryKey2 + "\t" + foreignKey2);
              return resultRelation;
         }

    You have to construct the second iterators inside the first while loop, otherwise you will always check against the value of the last key in the first iterator.
    private static Map equiJoin(Map relation1, Map relation2){
         Map resultRelation = new TreeMap();
         Iterator keys1Iterator = relation1.keySet().iterator();
         Iterator values1Iterator = relation1.values().iterator();          
         while (keys1Iterator.hasNext()){
              String primaryKey1 = (String)keys1Iterator.next();
              String foreignKey1 = (String)values1Iterator.next();
              Iterator keys2Iterator = relation2.keySet().iterator();
              Iterator values2Iterator = relation2.values().iterator();
              while (keys2Iterator.hasNext()){          
                   String primaryKey2 = (String)keys2Iterator.next();
                   String foreignKey2 = (String)values2Iterator.next();
                   if (foreignKey1 == primaryKey2)
                        resultRelation.put(primaryKey1, primaryKey2 + "\t" + foreignKey2);
         return resultRelation;
    }

  • I can't see my Gmail messages or attachments in Firefox, only the subject line, but I can in IE or when accessing from my Android.

    I use Firefox 7.0.1 on my desktop using Windows 7. As of yesterday I can no longer view my messages in Gmail when I click on them using Firefox. A window comes up, but it just shows the subject line, not the rest of the message. I can see them in Outlook, and I can see them in Gmail from IE or from my Android.

    This is only happening on my e-mail account, My mail will open in Explorer fine, but in Firefox it only shows the subject, it shows the rest of the message in a separate tab if I try to print the message.
    My wife was able to open her gmail on a separate tab, and hers loaded just fine, subject and the rest of the message but on mine, I can only see the message and the Google adds, grrrrr please help!!! is this an Issue with Gmail???

  • Does anyone see the green ball with this code in Flash Pro CC?

    If you can see the green ball at the top let me know what you did, thanks. I have Windows 8 PhotoShop CC.  I am very new when I only have the code below open in Flash saved as a ".as" when I press CTRL+ENTER nothing happens. The problem I believe is when I open another new document or ".fla" file and when it allows me to preview the screen after pressing CTRL+ENTER there should be a green ball at the top of the page, but there isn't
    P.S. WHen I click F-9 to bring up the code and then CTRL+ENTER its just a blank screen with #333333 as the stage color size 640 X 480 and 30 Frame Rate
    package{
         import flash.display.Sprite;
         import flash.events.Event;
         import Box2D.Dynamics.*;
         import Box2D.Collision.*;
         import Box2D.Collision.Shapes.*;
         import Box2D.Common.Math.*;
         public class Main extends Sprite{
              private var world:b2world;
              private var worldScale:Number=30
              public function Main(){
                   world =new b2World(new b2Vec2(o,9.81),true);
                   var bodyDef:b2BodyDef=new b2BodyDef();
                   bodyDef.position.Set(320/worldScale,30/worldScale);
                   var circleShape:b2CircleSHape;
                   circleShape=new b2CircleShape(25/worldScale);
                   var fixtureDef:b2FixtureDef = new b2FixtureDef();
                   fixtureDef.shape=circleShape;
                   var theBall:b2Body=world.CreateBody(bodyDef);
                   theBall.CreateFixture(fixtureDef);
                   var debugDraw:b2DebugDraw=new b2DebugDraw();
                   var debugSprite:Sprite=new Sprite();
                   addChild(debugSprite);
                   debugDraw.SetSprite(debugSprite);
                   debugDraw.SetDrawScale(worldScale);
                   debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
                   debugDraw.SetFillAlpha(0.5);
                   world.SetDebugDraw(debugDraw);
                   addEventListener(Event.ENTER_FRAME,updateWorld);
              private function updateWorld(e:Event):void {
                   world.Step(1/30,10,10);
                   world.ClearForces();
                   world.DrawDebugData();

    confirm using the trace function shown below.  what do you see in the output panel when testing your app?:
    package{
         import flash.display.Sprite;
         import flash.events.Event;
         import Box2D.Dynamics.*;
         import Box2D.Collision.*;
         import Box2D.Collision.Shapes.*;
         import Box2D.Common.Math.*;
         public class Main extends Sprite{
              private var world:b2world;
              private var worldScale:Number=30
              public function Main(){
    trace(this);
                   world =new b2World(new b2Vec2(o,9.81),true);
                   var bodyDef:b2BodyDef=new b2BodyDef();
                   bodyDef.position.Set(320/worldScale,30/worldScale);
                   var circleShape:b2CircleSHape;
                   circleShape=new b2CircleShape(25/worldScale);
                   var fixtureDef:b2FixtureDef = new b2FixtureDef();
                   fixtureDef.shape=circleShape;
                   var theBall:b2Body=world.CreateBody(bodyDef);
                   theBall.CreateFixture(fixtureDef);
                   var debugDraw:b2DebugDraw=new b2DebugDraw();
                   var debugSprite:Sprite=new Sprite();
                   addChild(debugSprite);
                   debugDraw.SetSprite(debugSprite);
                   debugDraw.SetDrawScale(worldScale);
                   debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
                   debugDraw.SetFillAlpha(0.5);
                   world.SetDebugDraw(debugDraw);
                   addEventListener(Event.ENTER_FRAME,updateWorld);
              private function updateWorld(e:Event):void {
                   world.Step(1/30,10,10);
                   world.ClearForces();
                   world.DrawDebugData();

  • Help Me , can't find what is wrong :S Simple code

    Hello everyone, im'm back =P ...well the problem is : I can't find what's wrong with this code above. The output shoul be "-1" but it prints -4 , it should print the min. value of an array. An absolute value to do that , its simple just do: e.g ( if ( n < 0 ) n = n * -1 ; and then check what is the min. value of the array. I just copied the content of the first array to the second .
    damn...what is wrong? :S
    public static void main (String[] xxx) {
         int [] array = {7,-4,-1,2}
        System.out.print( "The shortest number is: "+ minValue(array));
          static int minValue(int [] x ) {
        int []  newarray = new int [x.length];
        int min = mat[0];
        for( int i = 0; i !=x.length; ++i) {
       if ( i < o)  i = i * -1;
       else i = i * 1;
        newarray[i] = x[i] ;    
            for (int i = 0; i != mat.length; ++i) {
          if ( min > mat[i] )  min = mat;
    }return min;
    Thanks!!! I realy need your help plz!

    Almost!!!!! :D
    it returns 1 , should return -1 LOLO this is an exercise for practice, because i've the final test tomorrow .
    Is the last one , and i'm getting annoying of it :P.
    That's why i copied the 1st to the 2� array (but without the signal).
    U must ignore the signal when it checks, but it must print the number even if it has the signal . E.g -1 , u check ignoring the signal and the ouput must be: -1
    :S

  • Crop Functio... what is wrong with this code???

    Hi all,
    I have created this method to crop my bufferedimage, but when i call it it does not seem to do anything. :(
    Can anyone see what is wrong with it please?
    Thank you for you help!
    Claire
    x
         public BufferedImage cropImage()
              mBufferedImageCrop = copy(mBufferedImage);
              Graphics grphc = mBufferedImageCrop.getGraphics();
              Rectangle desiredArea = new Rectangle(10,10,10,10);
              BufferedImage sub_bi = mBufferedImageCrop.getSubimage(desiredArea.x, desiredArea.y,
                                                                                 desiredArea.width, desiredArea.height);
              grphc = mBufferedImageCrop.getGraphics();
              grphc.drawImage(sub_bi, desiredArea.x, desiredArea.y, this);
              repaint();
              return sub_bi;
         }I call this method using:
    displayPanel.cropImage();
    displayPanel.validate();
    repaint();Thanx

    I worked out the problem!
    :)

  • My ipad's screen has gone completely blank. I can't see anything. Have attempted to update and restore it, but to no avail. Does anyone have an idea on how to resolve this issue?

    My ipad's screen has gone completely blank. I can't see anything. Have attempted to update and restore it, but to no avail. Does anyone have an idea on how to resolve this issue?

    Try Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • A few months back I Dropped my iPhone 4 and I cracked my screen and now i cant unlock my phone due to touchscreen not working plus there are blured lines across the screen and I can't see anything that it displays. Now when I try too connect my iPhone 4 t

    A few months back I Dropped my iPhone 4 and I cracked my screen and now i cant unlock my phone due to touch screen not working plus there are blurred lines across the screen and I can't see anything that it displays.
    Now when I try too connect my iPhone 4 to iTunes on my computer at home an error message comes up saying that I have to unlock my iPhone 4 for it to communicate to my device.
    But the problem is that I can't unlock my iPhone 4 because I'm unable to see the key pad and my touch screen no longer responds when I touch it.
    I just want to reset my iPhone 4 back to its Factory Settings & start all over from the beginning.
    How can I unlock my iPhone 4 with iTunes on my computer or any other option you suggest me trying.
    Thank you in advance,
    SiHero

    If you have had a "local guy "repair your iphone you will not get any support from Apple for warranty OR post warranty
    If Verizon return it to Apple it wil not be handled by Apple
    If Verizon also use unauthorised repairers you may be lucky
    (Apple do not sell parts to local guys or anyone else )

  • Can't see anything in external drive after renaming a folder

    Hi all,
    I can't see anything on my external drive after renaming a folder. I have the drive set up as a Windows drive with access through the volumes folder (I had to transfer  large amount of files from a PC and have it be readable on my MacBook Air); I read a FAQ to set it up a few months ago and it has been working fine since then. I saw the same issue come up with a PC HD on a PC, but the solution was for a PC. I don't see anything else like that in the support community (or if it's there, then I'm not searching for it the right way). There is no partition on the drive and it still shows as having the same amount of data written on the drive as before the accident.
    Many thanks in advance!
    anj

    If you upgrade the your router, it would be the firmware that will be upgraded. For more information regarding upgrading the firmware, try this link.
    For your external drive, you might need to map the drive again with a different name.
    Hope this helps.

  • Can anyone tell me how to do this in Flash? See the following link?

    Can anyone tell me how to do this in Flash? See the following
    link?
    See this link. I want to know how to create the painting
    excercise as made here.
    http://disney.go.com/disneychannel/playhouse/littleeinsteins/activities/paint.html

    Start by looking at the drawing api for AS

  • We have a movie downloaded on a laptop connected to the internet pluged into our router in the basement and an apple tv upstairs trying to play the movie through home sharing but it wont play. can anyone tell me whats wrong?

    we have a movie downloaded on a laptop connected to the internet pluged into our router in the basement and an apple tv upstairs trying to play the movie through home sharing but it wont play. can anyone tell me whats wrong? it comes to the last loading page where it shows the desscription of the movie befor it acually plays.

    It can come about without any change done by the user, and it's not just from other networks. The placement of the router can also affect performance. Also make sure router is up to date.
    Apart from that would be the reboots.

  • I can't find preferences for the notes app. and every once in awhile some of my notes just disappear at start up, I see the name and then it refreshes and they are gone, very annoying. Can anyone tell me why it does this and how to stop it? thanks

    I can't find preferences for the notes app. and every once in awhile some of my notes just disappear at start up, I see the name and then it refreshes and they are gone, very annoying. Can anyone tell me why it does this and how to stop it? thanks

    Hi again, I am on an iMac using OSX 10.7.5, I"ve taken screenshots to show you I think my settings are correct

Maybe you are looking for