Ask Experts Questions for FREE Help !
Ask
    Gajendran3's Avatar
    Gajendran3 Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 19, 2013, 07:40 AM
    How to use If statement in Java
    I want a program in which it should ask a input from the user (eg, line 200 100, Move 200 100, circle 50) and it should draw in the graphic screen. The program should not stop until we press "end" it should keep drawing for all the commands. But in the below codes which I have attached I can run the code only once either circle or line. Please help me out to run all the command continuously.


    import java.util.Scanner;

    Public class MainFile2 {

    /**
    * @param args
    */
    public static void main(String[] args) {



    Scanner s = new Scanner(System.in);

    System.out.print("Enter the value to draw :");
    String text = s.nextLine(); // define some text

    String [] splitupText = text.split(" "); // split the text into multiple elements, and store in an array of String




    GraphicsScreen g = new GraphicsScreen();

    String line = splitupText[0];

    while ( line.equals("stop") == false){

    if ( line.equals("line")){

    if ( splitupText.length == 3 ) {
    int x = Integer.parseInt(splitupText[1]);
    int y = Integer.parseInt(splitupText[2]);

    g.lineTo(x, y);
    }
    else {
    System.out.println("Enter a correct Integer");
    }

    }

    else if (line.equals("circle")){

    int r = Integer.parseInt(splitupText[1]);

    g.circle(r);

    }

    System.out.print("Enter another value : ");
    line = s.nextLine();
    }
    g.close();
    s.close();

    }
    }
    Scleros's Avatar
    Scleros Posts: 2,165, Reputation: 262
    Hardware Expert
     
    #2

    Nov 30, 2013, 09:41 AM
    Think you should split more.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...

Prepare the income statement and the statement of owner equity for the calendar year [ 0 Answers ]

No. Account Title Debit Credit 101 Cash.. . $ 6,400 104 Short- term investments.. . 10,200 126 Supplies.. . 3,600 128 Prepaid insurance.. . 800 167 Equipment.. . 18,000 168 Accumulated depreciation— Equipment.. . $ 3,000 173 Building.. . 90,000 ...

Prepare the income statement and the statement of owner's equity in 2009 for Myra Co. [ 1 Answers ]

No. Account Title Debit Credit 101 Cash $7,500 104 short term investment 23,500 126 supplies 8,100 128 Prepaid insurance 8,600 167 Equipment 40,000 168 Accumulated depreciation-Equipment $20,000 173 Building 177,000 174 Accumulated depreciation-Building 59,000 183 Land 68,120

Multiple-step income statement in good form and retained earnings statement [ 1 Answers ]

Hi I would like someone to check to see if I did this correctly, if I did not then please help. Thanks The Problem is: The following pretax amounts pertain to River Corp. for the year ended December 31, 2008. Sales... $400,000 Operating Expenses... 84,000 Extraordinary gain... 30,000...


View more questions Search