Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › help convert from pseudo code to java
New Posts  All Forums:Forum Nav:

help convert from pseudo code to java

post #1 of 6
Thread Starter 
Write a program that prints a diamond with a plus within it, given the height of the diamond. The outer-most shape is a normal
diamond shape, the middle row of the shape will be a row filled with stars (making the horizontal dash of the plus sign), and in
all the remaining rows the middle element of that row will have a star (making the vertical dash of the plus sign).


string toprint = "";
// for each row
for(int row=0; row
toprint = "";
if(row==0){
// leading spaces = n/2
foreach(0 to n/2) toprint += " ";
toprint += "*";
}
else if((row>0)&&(row
// leading spaces = n/2 - row number
foreach((n/2)-row) toprint += " ";

// 3 stars in each row>0 && row < n/2
for(int i=0; i<3; i++){
toprint +="*";
string spaces = "";

// spaces between stars = row number -1
foreach(0 to row-1) spaces += " ";
toprint += spaces;
}
}
else if(row==n/2){
foreach(0 to n){
toprint += "*";
}
}
else if((row>n/2)&&(row
foreach(0 to row-(n/2)) toprint += " ";

// 3 stars in each row>n/2 && row < n-1
for(int i=0; i<3; i++){
toprint +="*";
string spaces = "";

// spaces between stars = n - row number-2
foreach(0 to n-row-2) spaces += " ";
toprint += spaces;
}
}
else if(row==n-1){
// leading spaces = n/2
foreach(0 to n/2) toprint += " ";
toprint = "*";
}
toprint += "\n";
}
print(toprint);
post #2 of 6
the point of this section is not to have other people do your hw for you. i explained all the logic for solving the problem and gave you about 80% of the code. i'm not trying to be a jerk but i feel like you took my pseudo code and are trying to get someone else to do your hw for you.
http://www.overclock.net/t/1235092/java-assignment-help-asap

all you have to do is put that in a main method, convert the foreach loops to normal for-loops, and print out the result. all three of those things you can learn from using google.

edit: btw, you didn't even copy n paste it correctly tongue.gif
Edited by travesty - 3/27/12 at 5:18pm
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #3 of 6
Thread Starter 
actually i did it it won't come out :
import java.util.*;
public class ali{
public static void main (String[]args){
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int m,x,i,k;
String line = "";
for(int row=0; row
line ="" ;
if(row==0){

for(m=0 ; m<= n/2 ; m++) {
line +=" " ;
line += "*" ;
}
}
else if((row>0)&&(row

for(m=0;m<=((n/2)-row); m++)
line +=" ";

// 3 stars in each row>0 && row < n/2
for(i=0; i<3; i++){
line +="*";
String spaces = "";

// spaces between stars = row number -1
for(x=0 ; x<=row-1 ;x++ )
spaces = " ";
line+=spaces ;
}
}
else if(row==n/2){
for(x=0 ;x<=n ; x++)
line+="*";

}
else if((row>n/2)&&(row
for(x=0 ;x<= row-(n/2);x++)
line+=" ";

// 3 stars in each row>n/2 && row < n-1
for(i=0; i<3; i++){
line+="*";
String spaces = "";

// spaces between stars = n - row number-2
for(x=0 ; x<=n-row-2 ; x++)
spaces += " ";
line+=spaces;
}
}
else if(row==n-1){

for(m=0 ; m<=n/2; m++)
line+=" ";
System.out.print("*");
}
line+="\n";
}
System.out.println(line);
}
}
post #4 of 6
Thread Starter 
Quote:
Originally Posted by travesty View Post

the point of this section is not to have other people do your hw for you. i explained all the logic for solving the problem and gave you about 80% of the code. i'm not trying to be a jerk but i feel like you took my pseudo code and are trying to get someone else to do your hw for you.
http://www.overclock.net/t/1235092/java-assignment-help-asap
all you have to do is put that in a main method, convert the foreach loops to normal for-loops, and print out the result. all three of those things you can learn from using google.
edit: btw, you didn't even copy n paste it correctly tongue.gif

actually i did it it won't come out and mind me iam a beginner and civil engineer and that's my first semester and i have to take CS
import java.util.*;
public class ali{
public static void main (String[]args){
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int m,x,i,k;
String line = "";
for(int row=0; row
line ="" ;
if(row==0){

for(m=0 ; m<= n/2 ; m++) {
line +=" " ;
line += "*" ;
}
}
else if((row>0)&&(row

for(m=0;m<=((n/2)-row); m++)
line +=" ";

// 3 stars in each row>0 && row < n/2
for(i=0; i<3; i++){
line +="*";
String spaces = "";

// spaces between stars = row number -1
for(x=0 ; x<=row-1 ;x++ )
spaces = " ";
line+=spaces ;
}
}
else if(row==n/2){
for(x=0 ;x<=n ; x++)
line+="*";

}
else if((row>n/2)&&(row
for(x=0 ;x<= row-(n/2);x++)
line+=" ";

// 3 stars in each row>n/2 && row < n-1
for(i=0; i<3; i++){
line+="*";
String spaces = "";

// spaces between stars = n - row number-2
for(x=0 ; x<=n-row-2 ; x++)
spaces += " ";
line+=spaces;
}
}
else if(row==n-1){

for(m=0 ; m<=n/2; m++)
line+=" ";
System.out.print("*");
}
line+="\n";
}
System.out.println(line);
}
}
post #5 of 6
Quote:
Originally Posted by alloka View Post

actually i did it it won't come out and mind me iam a beginner and civil engineer and that's my first semester and i have to take CS
my apologies then. i'm glad that you tried it on your own first. btw, use the code tags so that your code formats properly.

ok, pretty much just remove all of the <= and replace with <.

also,
Code:
if(row==0){
  for(m=0 ; m<= n/2 ; m++) {
    line +=" " ;
  }
  line += "*" ;
}

.......

// spaces between stars = row number -1
for(x=0 ; x<row-1 ;x++ ){
        spaces = " ";
        line+=spaces ;
}

.......

  else if(row==n-1){
    for(m=0 ; m<n/2; m++)
        line+=" ";
    line+="*";
  }
  System.out.println(line);
  }

i think that should pretty much fix it for you thumb.gif
Edited by travesty - 3/27/12 at 5:58pm
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #6 of 6
Thread Starter 
i think that should pretty much fix it for you thumb.gif[/quote]
thankx again very much smile.gifsmile.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › help convert from pseudo code to java