Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with basic program

807598Oct 26 2006 — edited Oct 26 2006
The program I am writing is supposed to ask the user to input a 4-digit Integer whose digits are not all the same, and then place the number in descending and ascending order, then subtract until the number 6174 is met.

I'm very new with java but I can't seem to get my if statement to loop back until the condition I want is met.

I know that a while statement will loop back, but when I tried that it just kept looping over and over again.

Any help and tips for later on in my project will be great.
import java.util.Scanner;


public class program2
 {
    public static void main(String[] args)
    {
      int      Number, D1, D2, D3, D4, Temp;
      Scanner  Keyboard = new Scanner(System.in);
      boolean  NoNumberYet;


      System.out.println("Please enter a 4-digit positive integer whose digits are all different: ");
      Number = Keyboard.nextInt();


      D1 = (Number/1000);
      D2 = (Number/100) %10;
      D3 = (Number/10) %10;
      D4 =  Number %10;

      NoNumberYet = true;

      while(NoNumberYet)  
        {
        if (D1 == D2 && D2 == D3 && D3 == D4)
           {
           NoNumberYet = false;
           System.out.println("The number you entered contains the same digits.");
           System.out.print("Please re-enter the number: ");
           Number = Keyboard.nextInt();
           }
        } 



    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2006
Added on Oct 26 2006
19 comments
177 views