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 1 of 1

Thread: Do while loop beak.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Do while loop beak.

    Hi, everyone! I have problem with my do while loop. I want to do, that user could break loop by him self. If I take int type variable it is okey, but when I try to do this with string or char it is does not working.
    This is my code fragment:
    import java.util.Scanner;
     
    public class lab2 {
    	public static void main(String args[]){
     
    		String breakLoop;
    		do{
    		double alfa,beta, reiskinys1, neigiamas, teigiamas;
     
    		Scanner input = new Scanner(System.in); // sukuriama bilioteka, kur saugomi ivesti duomenys
    		System.out.println("Insert Alfa:");
    		alfa = input.nextDouble();
    		System.out.println("Insert Beta:");
    		beta = input.nextDouble();
     
    		reiskinys1 = 2*((Math.cos(0.5*(alfa+beta)))*Math.cos(0.5*(alfa-beta))); 
    		System.out.println(reiskinys1);
     
    		lab2 X = new lab2();
     
    		if (reiskinys1 > 0){
    			neigiamas=reiskinys1*(-1);
    			System.out.println("Gautas skaicius: "+reiskinys1+" paverstas i neigiama: "+neigiamas);
    			X.naujas(neigiamas);
    		} else if (reiskinys1 < 0){
    			teigiamas=reiskinys1*(-1);
    			System.out.println("Gautas skaicius: "+reiskinys1+" paverstas i teigiama: "+teigiamas);
    			X.naujas(teigiamas);
    		} else {
    			System.out.println("Gautas skaicius lygus 0, todel ir lieka toks pats: "+reiskinys1);
    			X.naujas(reiskinys1);
    		}
    		System.out.println("IF YOU WANT TO BREAK PRESS N");
    		breakLoop = input.next();
    		} while(breakLoop!="N");
    	}



    Problem SOLVED.
    Last edited by Beniens; February 18th, 2012 at 07:47 AM. Reason: SOLVED


Similar Threads

  1. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 08:57 PM
  2. For loop; Problems with my for loop
    By mingleth in forum Loops & Control Statements
    Replies: 5
    Last Post: November 16th, 2011, 07:24 PM
  3. [SOLVED] My while loop has run into an infinite loop...?
    By kari4848 in forum Loops & Control Statements
    Replies: 3
    Last Post: March 1st, 2011, 12:05 PM
  4. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 03:09 AM
  5. hi. i want to rewrite this do loop into a while loop.
    By etidd in forum Loops & Control Statements
    Replies: 3
    Last Post: January 26th, 2010, 05:27 PM