Need tips on my program

Hi guys,
I'm trying to create a program that prints a rectangle using the letter a and prints a space inside the shape but I can't seem to find the error.
Here's my code:
class Rectangle
public static void printRect()
char c;
int positionOne = 1;
int width = 6;
int height = 4;
for (int b = 1;b <= width; b++)
System.out.print("a");
System.out.println();
int d = 1;
for (int c = 1; c <= width; c++)
if (int d = positionOne || int d = width)
System.out.print("a")
else
System.out.print();
public static void main (String [] args)
printRect();
I would really appreciate your help. Thanks.
Edited by: bladenking on Nov 27, 2007 4:16 PM

there were several mistakes.
class Rectangle"Rectangle" is already the name of a Java class so
you should change the class name.
if (int d = positionOne || int d = width)also equality checks use == not =.
also you shouldnt (re)declare the variable d in the if statement
- you need another for loop for the height.
- your variable names are awful. they need to be more descriptive
- the variable name "i" (for "iteration") is the standard for for loops (where appropriate)
- loops usually start with 0 and end at < boundary (when appropriate)
- comments make code more readable
- note that its possible to put top/bottom into the main body loops with clever if-ing
etc etc
please use [ code] [ code] (no space) tags when posting code
public class MyRectangle{
public static void main(String[] args){
     (new MyRectangle()).printRect();
public void printRect(){
     int width = 6;
     int height = 4;
     // top
     for (int i = 0; i < width; i++){
     System.out.print("a");
     System.out.println();
     // body
     for(int y = 0; y < (height - 2); y++){
     for(int x = 0; x < width; x++){
     if(x == 0 || x == (width - 1)){
     System.out.print("a");
     } else {
     System.out.print(" ");
     System.out.println();
     // bottom
     for (int i = 0; i < width; i++){
     System.out.print("a");
     System.out.println();
}

Similar Messages

  • I have a fully paid subscription to CC and use of installed programs but I can no longer sign in to CC. It repeatedly says "You've been signed out". I have the need to install another program but I can't sign in.

    I have a fully paid subscription to CC and use of installed programs but I can no longer sign in to CC. It repeatedly says "You've been signed out". I have the need to install another program but I can't sign in.

    Sign Out When Sign In http://forums.adobe.com/thread/1450581?tstart=0 may help
    -and http://helpx.adobe.com/creative-cloud/kb/unable-login-creative-cloud-248.html

  • Need to start a program in Oracle System (External) from sap program

    Hi guys,
         I need to start a program in another oracle based system from sap program by writing native sql statements.
    Does anyone have idea how to do this.
    Rgds,
    Ram

    Hi,
    Here is another sample for procedures.Kindly reward points by clicking the star on the left of reply,if it is useful.
    Code Sample for writing a procedure with input and output parameters
    REPORT zzz_jaytest.
    * Getting the regno and total as input parameters
    PARAMETERS : p_regno(10) TYPE c DEFAULT 'R1000',
                               p_total     TYPE i.
    data : v_total type i.
    * In this procedure, we are updating the total of a regno given as input.
    * Here two parameters used in the procedure are input parameters.
    * We are updating the record of regno entered in selection screen and
    * adding the total entered to the already existing total. We have to give semicolon
    * for the statement inside procedure.
    exec sql.
    CREATE or replace PROCEDURE PROC1 ( p_regno in char, p_total in number )
    IS
        BEGIN
          UPDATE stu_det SET total = total + p_total where regno = p_regno;
        END;
    endexec.
    * This is the code to execute the procedure for update.
    * While executing the procedure, the parameter variable should be
    * preceded with colon  :
    EXEC SQL.
      EXECUTE PROCEDURE PROC1 ( in :p_regno, in :p_total )
    ENDEXEC.
    * In this procedure, we are selecting the details for the regno entered
    * as input. Here p_regno is input parameter and v_total is used as output
    * parameter. So that we can use the retrieved value of v_total in our
    * ABAP program
    exec sql.
    CREATE or replace PROCEDURE PROC2 (p_regno in char, v_total out char)
    IS
        BEGIN
          select total into v_total from stu_det
                             where regno = p_regno;
        END;
    endexec.
    * This is the code to execute second procedure.
    EXEC SQL.
      EXECUTE PROCEDURE PROC2 ( in :p_regno, out :v_total )
    ENDEXEC.
    write : / 'Total of ', p_regno, ' is ', v_total.

  • I need to add a program to my laptop, but I have forgotten my password.  How can I reset it?

    need to add a program to my laptop, but I have forgotten my password.  How can I reset it?

    Solution may be found if you search in the "More Like This" section over in the right column.

  • Do I need an anti-virus program on a MacBook?

    I'm a brand new MacBook user. Just bought the 13-inch aluminum body version from Club Mac and it was delivered yesterday. The notebook is actually for my wife to be able to use while she's recovering from knee surgery in a couple of weeks and I thought it was time to branch our family out from PC's and Windows. So I'm setting up the MacBook for her to be able to use it...and for our family to get more literate on a Mac and it looks great! My question is do I need an anti-virus program and if so, which is a good one recommended by Mac users? NOTE: because my wife is familiar with Windows, I had XP service pack 3 installed and have VM Ware Fusion onboard to be able to run both Windows and Leopard for her convenience and to assist us. So there MAY be some Windows use on this MacBook, at least at first. All responses, replies, suggestions, welcome. THANK YOU.

    Do You Need Anti-Virus Protection for Your Mac?
    According to Rich Mogull's article, Should Mac Users Run Antivirus Software?,
    "The reality is that today the Mac platform is relatively safe. There are hundreds of thousands of viruses and other malicious software programs floating around for Windows, but less than 200 are known to target the Mac, and many of those are aimed at versions of the Mac OS prior to Mac OS X (and thus have no effect on a modern Mac).
    It's not that Mac OS X is inherently more secure against viruses than current versions of Windows (although it was clearly more secure than Windows prior to XP SP2); the numerous vulnerabilities reported and patched in recent years are just as exploitable as their Windows equivalents. But most security experts agree that malicious software these days is driven by financial incentives, and it's far more profitable to target the most dominant platform."
    Mr. Mogull is a computer security expert. I recommend reading the entire article as it is quite informative.
    For additional information on viruses, trojans, and spyware visit The XLab FAQs and read the FAQs on viruses and spyware.

  • I want to upgrade my MacBook Pro 5,2 to Lion, but specs says i need intel core 3 and i have intel core 2, there will be a problem? my computer will run slow? I will need to reinstall my programs again?

    I want to upgrade my MacBook Pro 5,2 to Lion, but specs says i need intel core 3 and i have intel core 2, there will be a problem? my computer will run slow? I will need to reinstall my programs again?
    Hardware Overview:
      Model Name:          MacBook Pro
      Model Identifier:          MacBookPro5,2
      Processor Name:          Intel Core 2 Duo
      Processor Speed:          2.8 GHz
      Number Of Processors:          1
      Total Number Of Cores:          2
      L2 Cache:          6 MB
      Memory:          8 GB
      Bus Speed:          1.07 GHz
      Boot ROM Version:          MBP52.008E.B05
      SMC Version (system):          1.42f4
      Sudden Motion Sensor:
      State:          Enabled

    Check to make sure your applications are compatible. PowerPC applications are no longer supported after 10.6.      
    Application Compatibility
    Applications Compatibility (2)

  • In need of a search program

    I need a desktop search program that can be set to search only one specific folder (or a specified group of folders) and extract files from within subfolders in those folders. The "result" summary must allow the files to be dragged and dropped or copy and pasted.
    The situation is that I have a lot (hundreds) of folders, each with four subfolders and these subfolders each have from one to three jpeg files (all different filenames). I'd like to collect these all in one place where I can sort them and place them such that they will be more readily accessable.
    They are so difficult to get at now, not knowing the filename.
    Can someone help me find such a program?
    Mootgramp

    Try the excellent freeware Easy Find - VersionTracker or MacUpdate.

  • HT1199 Hai, i tried to open itunes on my windows 8 laptop but it comes out with 'iTunes has stop working' notification and need to close the program everytime i try to load it. Please help! thanks.

    Hai, i tried to open itunes on my windows 8 laptop but it comes out with 'iTunes has stop working' notification and need to close the program everytime i try to load it. Please help! thanks.

    Hi ajay-9,
    Thanks for visiting Apple Support Communities.
    The steps in this article can help if iTunes is quitting unexpectedly on your PC:
    iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues
    http://support.apple.com/kb/ts1717
    Cheers,
    Jeremy

  • Need to Trigger a Program in ECC after the DSO load has completed

    HI Experts,
    I have scenario where i need to trigger a Program in ECC after the load to DSO has been completed successfully. Basically opposite of the everyday scenario.
    Can i still use the  the RSSM_EVENT_RAISE FM in the program to call the event in ECC.
    If the above is true.Do i need to have code in the program to confirm the DSO has been loaded or can i just have the program (which basically calls the FM RSSM_EVENT_RAISE) appended to the process chain after the DSO Activation?
    Appreciate your advice

    Hi,
    To help future proof your solution, lean towards using the process chain as much as possible.
    A "Green/Success" only link from the DataStore Activation process variant to an ABAP Program process variant will work nicely. It will also still allow your program to be executed by other scenarios (like manually because you want the event raised now without any dependency on the DataStore status).
    SAP now recommends you use the CL_BATCH_EVENT class and it's methods to interact with the system events. Use transaction SE24 to review the methods and parameters available and then use the sample code below to test your solution.
    Here is a starting point for coding that is used within an ABAP Program process variant in a process chain.
    Use transaction SE38 to store this code to be called by the ABAP Program process variant.
    constants:
      c_interrupt_eventid   type btceventid  value '[Event]',
      c_interrupt_eventparm type btcevtparm  value '[Parameter]'.
    data:
      l_interrupt_eventid   type btceventid value c_interrupt_eventid,
      l_interrupt_eventparm type btcevtparm value c_interrupt_eventparm.
    call method cl_batch_event=>raise
      EXPORTING
        i_eventid                      = l_interrupt_eventid
        i_eventparm                    = l_interrupt_eventparm
      EXCEPTIONS
        excpt_raise_failed             = 2
        excpt_server_accepts_no_events = 3
        excpt_raise_forbidden          = 4
        excpt_unknown_event            = 5
        excpt_no_authority             = 6
        others                         = 1.
    if sy-subrc <> 0.
      message e051(rsar) with 'Failed to raise background event.' c_interrupt_eventid c_interrupt_eventparm.
    endif.
    Note: The error message is process chain friendly and will appear in the RSPC transaction GUI and system logs.
    Hope this helps,
    John.

  • Need help writing host program using LabView.

    Need help writing host program using LabView.
    Hello,
    I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
    I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
    eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
    My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
    I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
    Any help would be appreciated.
    Regards, George
    George Dorian
    Sutter Instruments
    51 Digital DR.
    Novato, CA 94949
    USA
    [email protected]
    m
    (415) 883-0128
    FAX (415) 883-0572

    George may not answer you.  He hasn't been online here for almost eight years.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Need help with inventory program!!! someone please help me!!!

    Ok I have to write this inventory program for one of my classes.
    For part one i needed to Create a product class that holds the item number, the name of product, the number of units in stock, and the price of each unit.
    Then create a java application that displays all of the above info plus the total value of the inventory. I have done this so far with success.
    For part two i needed to modify the program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time including the item number, the name of the product, the number of units in stock, the price per unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
    so create a method to calculate the value of the entire inventory.(i did this)
    and create another method to sort the array items by the name of the product. ( i did this)
    The program compiles and runs fine except it is not doing anything from part two. It just does the same thing that it did when i wrote part one.
    Does anyone know why or what i need to do to my code.
    Here is my code.
    import java.util.Scanner; // program uses class Scanner
    import java.util.Arrays;
    class ProductList
      Product[] products = new Product[100]; // an array of 100 pruducts
      private void populate() {
        products[0] = new Product(0, "Good Luck Chuck"      , 25, 4.95);
        products[1] = new Product(1, "The Bourne Identity"  ,  3, 7.95);
        products[2] = new Product(2, "The Reaping"          ,  5, 8.99);
          products[3] = new Product(3, "Deja Vu"              ,  2,12.99);
          products[4] = new Product(4, "I Know Who Killed Me" ,  3,10.95);
      private void sortByTitle() {
      private void print() {
        for(int i=0; i<products.length; i++) {
          System.out.println(products);
    private void printTotalInventoryValue() {
    System.out.println("Total Inventory Value = "+calculateTotalInventoryValue());
    private double calculateTotalInventoryValue() {
    double total = 0D;
    for(int i=0; i<products.length; i++) {
    total += products[i].calculateInventoryValue();
    return total;
    public static void main( String args[] ) {
    ProductList list = new ProductList();
    list.populate();
    list.sortByTitle();
    list.print();
    list.printTotalInventoryValue();
    } class Product
    private int id;
    private String title;
    private int stock;
    private double price;
    public Product(int id, String title, int stock, double price) {
    setId(id);
    setTitle(title);
    setStock(stock);
    setPrice(price);
    public int getId() { return this.id; }
    public void setId(int id) { this.id = id; }
    public String getTitle() { return this.title; }
    public void setTitle(String title) { this.title = title; }
    public int getStock() { return this.stock; }
    public void setStock(int stock) { this.stock = stock; }
    public double getPrice() { return this.price; }
    public void setPrice(double price) { this.price = price; }
    public double calculateInventoryValue() {
    return getStock() * getPrice();
    public class Inventorypt2
    private String ProductInfo; // call class product info
    public static void main(String args[])
    //create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );
    int num; // product's item number
    int stock; // number of items in stock
    double price; // price each of item
    ProductInfo product; // product information instance
    System.out.println(); // blank line
    String name = "go";
    // loop until sentinel value read from user
    while ( !name.equalsIgnoreCase ("stop") )
    System.out.print( "Enter DVD title, or STOP to quit: "); // prompt
    name = input.nextLine(); // read item name from user or quit
    System.out.print( "Enter the item number: "); // prompt
    num = input.nextInt(); // read item number from user
    while ( num <=0 ) //loop until item number is positive
    System.out.println ("Item number must be positive. Please re-enter item number: ");//prompt user to re-enter item number
    num = input.nextInt(); // read item number
    } //end while
    System.out.print( "Enter the quantity in stock: "); // prompt
    stock = input.nextInt(); // read stock quantity from user
    while ( stock <0 ) //loop until stock is positive
    System.out.println ("Quantity in stock can not be less than zero. Please re-enter the quantity in stock: ");//prompt user to re-enter quantity in stock
    stock = input.nextInt(); // read stock quantity from user
    } //end while
    System.out.print( "Enter the price of DVD: "); // prompt
    price = input.nextDouble(); // read item price from user
    while ( price <=0 ) //loop until price is positive
    System.out.println ("Product price must be positive. Please re-enter the price of the product: ");//prompt user to re-enter product price
    price = input.nextDouble(); // read item price from user
    } //end while
    product = new ProductInfo( num, name, stock, price); // initialize ProductInfo variables
    System.out.println(); // blank line
    System.out.printf( "Item Name: %S\n", product.getName());
    System.out.printf( "Item Number: %s\n", product.getNum());
    System.out.printf( "Qty. in Stock: %s\n", product.getStock());
    System.out.printf( "Price Each: $%.2f\n", product.getPrice());
    System.out.printf( "Total Value in Stock: $%.2f\n", product.getInventoryTotal());
    System.out.println(); // blank line
    System.out.print( "Enter DVD title, or STOP to quit: "); // prompt
    name = "";
    while ( name.equals("") )
    name = input.nextLine(); // read new product name from user or quit
    } //end while
    System.out.println(); // blank line
    System.out.println("Good Bye!"); // exit message
    Edited by: jay1981 on Mar 16, 2008 2:07 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You will get more help if your code is formatted better:
    * Only post code that is already formatted correctly including indentations.
    * Get rid of all those comments cluttering up your code.
    * Make sure your posted code compiles without need for any changes. Yours doesn't at present. Where is the ProductInfo class?
    Again, you want it easy for a volunteer here to read your post, otherwise he/she simply won't do it. Good luck.

  • Need to add my program to excute when windows welcome

    Hello everybody!
    I need to add my program to excute when windows startup. I want my program run same Windows Update when startup.
    I need windows welcome wait my program end and next to login user
    Thank everybody

    Use local group policy editor.

  • Need help in pda programming

    Hi, I am new on pda programming. I already develop a java program using j2sdk1.4.2_05. I need to run this program in pda for my final project. Can i do this using creme? What version do i must use?
    If j2sdk1.4.2_05 can't, does jdk1.3.1 can?
    And anybody know where can i find pocket pc emulator so i can test my program on pc?
    Many Thanks before,
    tinna

    hi,
    I am currently doing a project in pda application. We are using jeode as a VM for the pda. But it uses java 1.2. Maybe you want to have a look at it. however u cant use the swing class in jeode and only awt is the class availlable for programming interfaces.
    If you need jeode u can contact me. I can give you a free copy which was availlable till last year as now it has gone chargable.
    Also do you have any idea about how can i read and write txt files or dat files from desktop using java. I want to use a usb cradle for connection.
    This information would be really appreciated as I need this for my second year project.

  • I can't open some pictures in emails, do I need to install a program

    I can't open some pictures in emails, do I need to install a program?

    No additional programs needed. What happens when you try to open them? What is the prompt?

  • I need a RAW converter program and the adovbe system has been recommended.  how shall I proceed?

    I need a RAW converter program and the Adobe system has been recommended.  How do I proceed?

    Seems you are looking for DNG Convertor, If so, here is the download link
    Adobe Camera Raw and DNG Converter for Windows : http://www.adobe.com/support/downloads/product.jsp?product=106&platform=Windows
    Adobe Camera Raw and DNG Converter for Macintosh : http://www.adobe.com/support/downloads/product.jsp?product=106&platform=Macintosh

Maybe you are looking for

  • Transferring from old iPod to new iPod

    I have an iPod mini, but have just got a new iPod. Some of the songs on my mini are from my old computer, so I no longer have them. Is it possible to transfer songs directly from iPod to iPod if they are no longer in iTunes?

  • Wrong CD Titles Displayed THIS IS A BUG IN OSX APPLE PLEASE FIX

    I've been having this same problem for YEARS. Can comeone at Apple please address this issue? Here's what happens. I load a custom CD that has never been in the machine before and it should just display this CD as "title" or some other generic notati

  • Substitution variable maxl from batch dynamic

    Hi, I have set up a batch file which is calling .msh file which changes my substitution variables. I am running this command: "alter database App2.Plan1 set variable 'ActMonth1' 'Jul';" "alter database App2.Plan1 set variable 'ActMonth2' 'Aug';" "alt

  • Sales Office copying from Sales order to Invoice ( order related billing)

    Hi In sales invoice (vf01) is there any field for Sales Office. In order related billing . how we can copy sales office from sales order to Invoice. Regards\Adnan

  • "Quit unexpectedly" for most of my apps from the Creative Cloud.

    "Quit unexpectedly" I've been having this issue for most of my apps from the Creative Cloud everytime I hooked up my MacbookPro to a ViewSonic VG2436 Series monitor. Once I un-hooked my laptop all my Creative Cloud apps works fine. Why is it causing