Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java - Help with a simple for loop.
New Posts  All Forums:Forum Nav:

Java - Help with a simple for loop.

post #1 of 2
Thread Starter 
Hey guys just a little lab i am doing I have to draw a triangle like this

**********
*********
********
*******
******
*****
****
***
**
*


So i wrote a loop for it
Code:
for (row = 0,column = 10;row < 10;row++,column--){
        
    for (spce = 0; spce < row;spce++)
      
    {
        System.out.print( " " );
        
    }
    
    
    for (spce =0;spce < column;spce++)
        
    {
        
         System.out.print( "*" );
         
    }
      
    System.out.print("\n");
    
}

Now I have to have the triangle upside down so I wrote this loop that is not printing anything.
Code:
for (row = 0,column = 0;row > 10;row++,column++){
        
    for (spce = 8; spce < row;spce--)
      
    {
        System.out.print( " " );
        
    }
    
    
    for (spce = 8; spce < column; spce--)
        
    {
        
         System.out.print( "*" );
         
    }
      
   // System.out.print("\n");
    
}

Even a hint as to what i have done wrong would be appreciated, im sure its a logical error I feel kinda silly having to ask since i managed the first triangle rolleyes.gif
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS HD7770 Series Corsair 8GB 2x 2GB 
Hard DriveOptical DriveCoolingOS
segate none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
Mid range build
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570k P8Z77-V ASUS HD7770 Series Corsair 8GB 2x 2GB 
Hard DriveOptical DriveCoolingOS
segate none corsair H80 windows 7 64 
MonitorPowerCaseMouse
Samsung s22b360 corsair tx 750 m NZXT phantom 410 (GM) logitech G400 
  hide details  
Reply
post #2 of 2
row is greater then 10
Code:
for (row = 0,column = 0;row > 10;row++,column++){

should be row is less than 10
Code:
for (row = 0,column = 0;row < 10;row++,column++){
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java - Help with a simple for loop.