New Posts  All Forums:Forum Nav:

im stuck in java - Page 4

post #31 of 35
Thread Starter 
ok heres the problem its not returning the proper number its supposed to reduce a fraction
Code:
    public static void Reducing(int Top, int Bottom) {
        boolean looper = true;
        while (looper == true) {
            int New1 = Top / Bottom;
            if (New1 % 2 == 0) {
                int TopFinal = Top;
                int BottomFinal = Bottom;
                looper = false;
                System.out.println(TopFinal + "/" + BottomFinal);
            }
            if (New1 % 2 != 0) {
                Top = Bottom;
                Bottom = New1;
            }
        }

    }
post #32 of 35
i was having the same problem with you...the frustration level 1st semester was insane...once you start to understand what is going on...things become much easier. I'm in my 2nd semester and I use google as my 2nd teacher so to speak.
Edited by surfbumb - 2/17/11 at 11:55pm
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #33 of 35
not a massive problem.. but never call vars with a capital letter to start. BottomFinal - bottomFinal. I used to get done for that in my first year.
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
post #34 of 35
I'm taking my first semester of Java now as well. It is crazy at first but slowly but surely it is beginning to make more sense.
Slow and Crappy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 960 Asus Rampage II Gene GTX480 6x 2GB Mushkin Redline 
Hard DriveOSPowerCase
OCZ Vertex 3 MaxIOPS 120GB / 2x WD RE4 2TB RAID 1 Windows 7 Ultimate 64-bit SP1 Corsair TX850 V2 Lian-Li PC-A04B 
  hide details  
Reply
Slow and Crappy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 960 Asus Rampage II Gene GTX480 6x 2GB Mushkin Redline 
Hard DriveOSPowerCase
OCZ Vertex 3 MaxIOPS 120GB / 2x WD RE4 2TB RAID 1 Windows 7 Ultimate 64-bit SP1 Corsair TX850 V2 Lian-Li PC-A04B 
  hide details  
Reply
post #35 of 35
I looked briefly at your code above, i'll give you some help...there are 3 scenarios:

Scenario 1....the top can be divided by the bottom....6/3....15/5...etc.

Code:
//scenario 1
if(Top%Bottom == 0)
     int newNum = Top/Bottom;
System.out.println(newNum);
Scenario 2....if you have 8/6...or a fraction that can be reduced...but the bottom does not go into the top
Code:
//scenario 2
if(Top%2 == 0 && Bottom%2 == 0){
     int newTop = Top/2;
     int newBottom = Bottom/2;
     System.out.println(newTop + "/" + newBottom);
}
//remember you can use %3 and Top/3...Bottom/3   if you have 21/15...etc.

Code:
//scenario 3
The fraction is already in its lowest form

Edited by surfbumb - 2/18/11 at 12:35am
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming