New Posts  All Forums:Forum Nav:

Java Help?

post #1 of 3
Thread Starter 
Hey Everyone,

So, for one of my tasks I have been set to create a program which prints out a certain number of variables and their values.
I have done that and printed out to what seemed to be the correct Outputs, Wrong.
I was suppose to print out the Four Variables in a sort of grid rather than One column.
So, I am asking how I can make the Outputs form a 4 x 4 Grid?

Here is the Code/Outputs:
Code
public class Integers
{
public static void main(String[] args)
{
int count, index, sum, average;//declare variables
count = 8;//Line 1
index = sum = count + 2;//Line 2
sum = count + index * 2;//Line 3
average = (count + sum + index) /3;//Line 4

System.out.println("Count___" + count);
System.out.println("Index___" + index);
System.out.println("Sum___" + sum);
System.out.println ("Average___" + average);
}
}

Outputs

Count___8
Index___10
Sum___28
Average___15


Outputs Design I Need


CountIndexSumAverage
Line 1 8000
Line 2 810100
Line 3 810280
Line 4 8102815


Sorry about the layout and Indentations While copying over the code the formatting didn't

Edit: Just Moved From The School Help Section to Here, Thought I Would Receive Better Help. (:
New Rig
(19 items)
 
Old Rig
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770k Asus p8Z77-V Deluxe (Socket LGA1155) GeForce GTX 680 8GB Mushkin Enhanced Blackline Frostbyte 
RAMHard DriveHard DriveHard Drive
8GB Mushkin Enhanced Blackline Frostbyte 2GB Western Digital Caviar Green WD10EARS Mushkin Chronos 180GB SSD 2 TB Samsung HDD 
Optical DriveCoolingOSMonitor
LG GH22Ns70 22x DVDRW Be Quiet! Dark Rock PRO 2 Dual Fan Windows 7 Home Premium 23" AOC 2341 
MonitorKeyboardPowerCase
23" AOC 2341 Saitek Cyborg V7 Keyboard 860W Seasonic P-860 Platinum  IN WIN Dragon Rider Black Full Tower 
MouseMouse PadAudio
Gigabyte GM-M6880 xRaider Flexiglow Mousepad Realtek Audio Sound Thingy 
CPUMotherboardGraphicsRAM
Intel Core i3 540 Gigabyte H55M-ED55 (MS-7635) Nvidia GTX 560Ti 6GB Mushkin Blackline 
Hard DriveOptical DriveOSMonitor
2TB Seagate Hard Drive 2x GH22Nss50 Windows 7 Home Premium 64-Bit 2x 23" AOC Monitors 
KeyboardPowerCaseMouse
Saitek Cyborg V7 Keyboard Serena 850W Lian Li PC-K58B Lancool (Beast) Microsoft Sidewinder x8 Mouse 
Mouse Pad
Flexiglow XRaider Mouse Pad 
  hide details  
Reply
New Rig
(19 items)
 
Old Rig
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770k Asus p8Z77-V Deluxe (Socket LGA1155) GeForce GTX 680 8GB Mushkin Enhanced Blackline Frostbyte 
RAMHard DriveHard DriveHard Drive
8GB Mushkin Enhanced Blackline Frostbyte 2GB Western Digital Caviar Green WD10EARS Mushkin Chronos 180GB SSD 2 TB Samsung HDD 
Optical DriveCoolingOSMonitor
LG GH22Ns70 22x DVDRW Be Quiet! Dark Rock PRO 2 Dual Fan Windows 7 Home Premium 23" AOC 2341 
MonitorKeyboardPowerCase
23" AOC 2341 Saitek Cyborg V7 Keyboard 860W Seasonic P-860 Platinum  IN WIN Dragon Rider Black Full Tower 
MouseMouse PadAudio
Gigabyte GM-M6880 xRaider Flexiglow Mousepad Realtek Audio Sound Thingy 
CPUMotherboardGraphicsRAM
Intel Core i3 540 Gigabyte H55M-ED55 (MS-7635) Nvidia GTX 560Ti 6GB Mushkin Blackline 
Hard DriveOptical DriveOSMonitor
2TB Seagate Hard Drive 2x GH22Nss50 Windows 7 Home Premium 64-Bit 2x 23" AOC Monitors 
KeyboardPowerCaseMouse
Saitek Cyborg V7 Keyboard Serena 850W Lian Li PC-K58B Lancool (Beast) Microsoft Sidewinder x8 Mouse 
Mouse Pad
Flexiglow XRaider Mouse Pad 
  hide details  
Reply
post #2 of 3
Code:
public class Integers
{
public static void main(String[] args)
{
String c = "count";
String i = "index";
String s = "sum";
String a = "average";
int count = 0;
int index = 0; 
int sum = 0; 
int average = 0; //declare variables
System.out.println(String.format("%22s %13s %12s %15s", c, i, s, a)); //prints header formatted
count = 8; //Line 1
System.out.println(String.format("Line 1 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 1 formatted
index = sum = count + 2; //Line 2
System.out.println(String.format("Line 2 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 2 formatted
sum = count + index * 2; //Line 3
System.out.println(String.format("Line 3 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 3 formatted
average = (count + sum + index) /3; //Line 4
System.out.println(String.format("Line 4 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 4 formatted

}
}
let me know if this works.
Edited by surfbumb - 11/4/11 at 5:05pm
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 #3 of 3
Thread Starter 
Quote:
Originally Posted by surfbumb View Post
Code:
public class Integers
{
public static void main(String[] args)
{
String c = "count";
String i = "index";
String s = "sum";
String a = "average";
int count = 0;
int index = 0; 
int sum = 0; 
int average = 0; //declare variables
System.out.println(String.format("%22s %13s %12s %15s", c, i, s, a)); //prints header formatted
count = 8; //Line 1
System.out.println(String.format("Line 1 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 1 formatted
index = sum = count + 2; //Line 2
System.out.println(String.format("Line 2 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 2 formatted
sum = count + index * 2; //Line 3
System.out.println(String.format("Line 3 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 3 formatted
average = (count + sum + index) /3; //Line 4
System.out.println(String.format("Line 4 %13d %13d %13d %13d", count, index, sum, average)); //prints Line 4 formatted

}
}
let me know if this works.
Yeah, This Code works fine, Thank You (:
New Rig
(19 items)
 
Old Rig
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770k Asus p8Z77-V Deluxe (Socket LGA1155) GeForce GTX 680 8GB Mushkin Enhanced Blackline Frostbyte 
RAMHard DriveHard DriveHard Drive
8GB Mushkin Enhanced Blackline Frostbyte 2GB Western Digital Caviar Green WD10EARS Mushkin Chronos 180GB SSD 2 TB Samsung HDD 
Optical DriveCoolingOSMonitor
LG GH22Ns70 22x DVDRW Be Quiet! Dark Rock PRO 2 Dual Fan Windows 7 Home Premium 23" AOC 2341 
MonitorKeyboardPowerCase
23" AOC 2341 Saitek Cyborg V7 Keyboard 860W Seasonic P-860 Platinum  IN WIN Dragon Rider Black Full Tower 
MouseMouse PadAudio
Gigabyte GM-M6880 xRaider Flexiglow Mousepad Realtek Audio Sound Thingy 
CPUMotherboardGraphicsRAM
Intel Core i3 540 Gigabyte H55M-ED55 (MS-7635) Nvidia GTX 560Ti 6GB Mushkin Blackline 
Hard DriveOptical DriveOSMonitor
2TB Seagate Hard Drive 2x GH22Nss50 Windows 7 Home Premium 64-Bit 2x 23" AOC Monitors 
KeyboardPowerCaseMouse
Saitek Cyborg V7 Keyboard Serena 850W Lian Li PC-K58B Lancool (Beast) Microsoft Sidewinder x8 Mouse 
Mouse Pad
Flexiglow XRaider Mouse Pad 
  hide details  
Reply
New Rig
(19 items)
 
Old Rig
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770k Asus p8Z77-V Deluxe (Socket LGA1155) GeForce GTX 680 8GB Mushkin Enhanced Blackline Frostbyte 
RAMHard DriveHard DriveHard Drive
8GB Mushkin Enhanced Blackline Frostbyte 2GB Western Digital Caviar Green WD10EARS Mushkin Chronos 180GB SSD 2 TB Samsung HDD 
Optical DriveCoolingOSMonitor
LG GH22Ns70 22x DVDRW Be Quiet! Dark Rock PRO 2 Dual Fan Windows 7 Home Premium 23" AOC 2341 
MonitorKeyboardPowerCase
23" AOC 2341 Saitek Cyborg V7 Keyboard 860W Seasonic P-860 Platinum  IN WIN Dragon Rider Black Full Tower 
MouseMouse PadAudio
Gigabyte GM-M6880 xRaider Flexiglow Mousepad Realtek Audio Sound Thingy 
CPUMotherboardGraphicsRAM
Intel Core i3 540 Gigabyte H55M-ED55 (MS-7635) Nvidia GTX 560Ti 6GB Mushkin Blackline 
Hard DriveOptical DriveOSMonitor
2TB Seagate Hard Drive 2x GH22Nss50 Windows 7 Home Premium 64-Bit 2x 23" AOC Monitors 
KeyboardPowerCaseMouse
Saitek Cyborg V7 Keyboard Serena 850W Lian Li PC-K58B Lancool (Beast) Microsoft Sidewinder x8 Mouse 
Mouse Pad
Flexiglow XRaider Mouse Pad 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming