Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: help java prog. adding do{ while()

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help java prog. adding do{ while()

    how will i add do{ while() to my program
    this is my program


    import java.util.*;
    public class Triangle {
    	Scanner br = new Scanner(System.in);
    	private double height;
    	private double base;
    	public Triangle(double h, double b){
    		height=h;
    		base=b;
    	}
     
    	public Triangle(){		
    		System.out.println("Enter Height of the Triangle: ");
        	double h=br.nextDouble();
        	height=h;
        	System.out.println("Enter Base of the Triangle: ");
        	double b=br.nextDouble();
        	base=b;
    	}
        public double getHeight() {
        	return height;
        }
            public double getBase() {
        	return base;
        }
            public void setHeight(double height) {
        }
            public void setBase(double base) {
        }
        public double getArea(){
        	double area=0;
        	area=0.5*height*base;
        	return area;
        }  
    	public static void main(String[] args){
    		Triangle tr = new Triangle();
    		System.out.println("The Area of a Triangle is: "+tr.getArea());
    	}
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: help java prog. adding do{ while()

    This is the first result for googling "java do while": The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    Read through that and try something.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog. adding do{ while()

    any more other guides??cant seem to make it work because of its many method i do not know where to place it

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: help java prog. adding do{ while()

    That's really going to depend on your exact goal. What do you want the do while to do, exactly?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog. adding do{ while()

    after The Area of a Triangle will be output a message that will say DO YOU WANT TO CONTINUE?? if i type Y then the program will reloop to the start where i will input the height etc. again

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: help java prog. adding do{ while()

    Quote Originally Posted by darking123 View Post
    after The Area of a Triangle will be output a message that will say DO YOU WANT TO CONTINUE?? if i type Y then the program will reloop to the start where i will input the height etc. again
    Sounds good to me. So what have you tried? Where are you stuck? After reading the tutorial I posted, what don't you understand?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog. adding do{ while()

    what i dont understand is placing the do and while in my program that has many method on it...can you guide me

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: help java prog. adding do{ while()

    do {
    someMethodCallThatDoesSomeCoolThing();
    while(theUserStillWantsToDoSomeCoolThing);
    }
    There are many examples available through any search engine using the keywords "java do while loop examples"

  9. #9
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help java prog. adding do{ while()

    yup sir i know how it works..but i do not know where to place it to me program because it has many methods on it

  10. #10
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: help java prog. adding do{ while()

    Quote Originally Posted by darking123 View Post
    yup sir i know how it works..but i do not know where to place it to me program because it has many methods on it
    You would place it where you want it... I don't know how else to say it...

    First you have a problem to be solved by a computer program.
    Second you decide how a program can solve the problem.
    Third you write code to perform the actions described in the solution.

    Where the solution says: "Do this thing while this condition" ... that is where it goes. All of the code to "do this" goes inside the loop.
    Tell ya what, why don't you just give it a try. Throw it in there where it looks good and see what it does. If it does not work we will help you figure out why.

    Sorry but no one is just going to give you the solution in code. (..and if they do it will be deleted)
    You just have to work through the problem solving process, trial and error, which will pay off the great rewards of experience and learning as you go.

Similar Threads

  1. help java prog
    By darking123 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 23rd, 2012, 05:24 PM
  2. help java prog
    By darking123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2012, 10:38 PM
  3. Help with prog please.
    By Flantoons in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 15th, 2011, 05:10 AM
  4. Socket related prog
    By amitabh in forum Java Networking
    Replies: 1
    Last Post: March 18th, 2011, 08:47 AM
  5. need help prog skipping method
    By Pulse_Irl in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 11th, 2010, 08:57 AM