programes on do... while

programes on do... while

  1. write a program to print reverse of a given digit
  2. write a program to check whether entered digit is palindrome or not
  3. write a program to check whether entered no. is Armstrong or not
View Answers

March 26, 2011 at 1:30 PM

1)

import java.util.*;

public class ReverseNumber {
    public static int reverse(int num){
        int n = num;
            int reversedNumber = 0;
            for (int i = 0; i <= num; i++) {
                int r = num % 10;
                num = num / 10;
                reversedNumber = reversedNumber * 10 + r;
                i = 0;
            }
            return reversedNumber;
    }
    public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            System.out.print("Enter number: ");
            int num = input.nextInt();
            System.out.println("Reversed Number: "+reverse(num));
    }
}

March 26, 2011 at 1:31 PM

2)

import java.util.*;

public class NumberPalindrome {
    public static void main(String[] args) {
        try {
            Scanner input = new Scanner(System.in);
            System.out.print("Enter number: ");
            int num = input.nextInt();
            int n = num;
            int reversedNumber = 0;
            for (int i = 0; i <= num; i++) {
                int r = num % 10;
                num = num / 10;
                reversedNumber = reversedNumber * 10 + r;
                i = 0;
            }
            if (n == reversedNumber) {
                System.out.print("Number is palindrome!");
            } else {
                System.out.println("Number is not palindrome!");
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

March 26, 2011 at 1:37 PM

3)

mport java.io.*;
class ArmstrongNumber{

public static void main(String args[]) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter number:");
int num = Integer.parseInt(bf.readLine());
int n = num; //use to check at last time
int check=0,remainder;
while(num > 0){
remainder = num % 10;
check = check + (int)Math.pow(remainder,3);
num = num / 10;
}
if(check == n)
System.out.println(n+" is an Armstrong Number");
else
System.out.println(n+" is not a Armstrong Number");
}
}









Related Tutorials/Questions & Answers:
programes on do... while
programes on do... while   write a program to print reverse of a given digit write a program to check whether entered digit is palindrome... to check at last time int check=0,remainder; while(num > 0){ remainder = num % 10
programes on while loop
programes on while loop   write a program to calculate sum of an entered digit write a program to find gcd and lcm of 2 positive integers   Java sum of digits Java Find LCM and GCD
Advertisements
The while and do
While and do-while      ... terminates. Have a look at do-while statement now. ADS_TO_REPLACE_3 Here is the syntax: do { statement(s) } while (expression); Lets
while and do while
while and do while  hello, What is the difference between a while statement and a do statement?   hello,ADS_TO_REPLACE_1 A while... should occur. A do statement checks at the end of a loop to see whether the next
While and do-while
While and do-while       Nested classes Here is another advantage of the Java, object-oriented programming language that allows us to define a class within another
php do while syntax
php do while syntax  How to create a do while loop in php. What is the syntax
php do while example
php do while example  Simple example of do while loop in PHP
php do while loop
php do while loop  Difference between do while loop and simple loop in PHP
php do while break
php do while break   receiving a Fatal saying cannot break/continue.. please suggest. Thank U
php do while false
php do while false   Is there any difference between FALSE and false
do-while loop
do-while loop  how many times will the following loop get executed and what will be the final value of the variable I after execution the loop is over. int I = 5; do{ I + = 3; System.out.println(""+I); I=I+1; }while(I>=9
while & do..while Loop
while & do..while Loop while loop The while loop iterate until provided... : Value of j 1Value of j 2Value of j 3 The do...while statement The do-while... : do   {   code to be executed;   } while (condition
Class.forName will do while loading drivers
Class.forName will do while loading drivers  What Class.forName will do while loading drivers
Do-while loop in Java
Do-while loop in Java In this section you will learn about do-while loop in Java. do-while loop is similar to while loop but the difference is do-while loop... condition repeatedly and run at least once. For that we need a do-while loop so
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
Do While Loop in Java
Do while loop in Java There are three loops most commonly used in Java e.g..... Do while loop is java is slightly different with While loop as in While loop... for the do-while loop:ADS_TO_REPLACE_1 do { statements; } while
do-while Loop in Java
do-while Loop in Java      ... and processes once at least. For that you have to use the do while loop in  after that check the condition then we use the do-while loop statement. do-while loop
do while loop
do while loop       In java a do while loop is a control flow statement that allows a certain code... with a condition associated with the while keyword. The code inside the do construct
PHP Do While Loop
Do-While Control Structure: Do-While loop is another type of loop which runs... within. We generally use Do-While loop  when the iteration must run at least once despite of the validity of the variable. In Do-While loop we need
PHP Do While Loop
Do-While Loop Function PHP: PHP Do-While loop method is another type of loop... the code within. We generally use Do-While loop  when the iteration must run at least once despite of the validity of the variable. In Do-While loop we need
Do..While Loops
3.10.2. Do…While Loops The do...while statement always execute..._TO_REPLACE_2 while (condition); e.g. Here we define i = 1, and then increment i with 1...; . $i . “<br />”;ADS_TO_REPLACE_5 } while ($i<=5); ?>
While and do-while
While and do-while      ... and the loop terminates. Have a look at do-while statement now. ADS_TO_REPLACE_3 Here is the syntax: do { statement(s) } while (expression); Lets
programes on switch
programes on switch   write a program to design menu driven..."); System.out.println("4 Division"); System.out.println("5 Exit"); do...; break; } } while(!exit); } }  
programes on array
programes on array  a. write a program to find max and min element... and back to decimal. c. write a program to do following:- i) addition of two...; while(num > 0){ rem = num % 10; num = num / 10
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
Use if, if else,for,while,do wile ad switch in same Java Class
Use if, if else,for,while,do wile ad switch in same Java Class  hi how to use if, if else,for,while,do wile ad switch in same class? very urgent... "); System.out.println("5. Exit"); boolean quit = false; do{ System.out.print("Please
programes on methods
programes on methods   write a program to implement bubble sort write a program to demonstrate call by value and call by reference.(pass objects as parameters) write a program to calculate factorial of a no. using recursive
programes on strings
programes on strings   a. write a program to copy one array to another array using System.arrayCopy() method. b. write a program to check whether entered string is palindrome or not.   Have a look at the following link
programes on if....else
programes on if....else   write a program to check whether entered year is leap year or not write a program to check whether entered no. ends with 5 or not write a program to find minimum of 3 nos using nested if else. write
How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?
How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?  this is count record code...); while (rs.next()) { rows =rs.getInt(1); %> <
Java Break while example
be used for terminating other loops as well such as while, do while etc. . Break... Java Break while example     ... the while loop is demonstrated.  In the program we breaking while loop under
Java error reached end of file while parsing
of file while parsing  occurred when a programmer do not close the class ... Java error reached end of file while parsing... of file while parsing ,In this code we want to display Time in hour, minute
PHP While Loop
are used namely for, while and do while. Apart from these there are some loops... tutorial we will study while, do while and for. ADS_TO_REPLACE_1 So let's get...While Loop in PHP: In programming language we need to use loops for executing
Erron while
Erron while   Hi, i'm doing a project regarding xml. I want to extract all nodes from body of existing xml doc to make another xml with that data.Here is my coding and error showing on that coding.Could anybody help to know my
reached end of file while parsing and while expected
reached end of file while parsing and while expected  import java.io....); do { if(input2=='c'||input2=='C') { degreesC=5*(temp-32)/9...; System.out.println("Fahrenheit:"+degreesF); System.out.println("Do you want to try
do the following
do the following  write a program to enter the string and do the following 1- count totle number of vowel 2- replace vowel 3- delete the charactor from given value 4- riverce the string 5- convert second word in upercase 6
Iterator Java While
The Java While loop Iterator is the top tested loop. It is in two forms while(), do while() While loop is mostly used with Iterator compared to for loop... .. while"); do { System.out.print(it1.next() + "\t"); } while
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
how to do this?
how to do this?   Given any integer 2D array, design then implement a Java program that will add to each element in the array the corresponding column number and the corresponding row number. Then, it prints the array before
php while loop
php while loop  Example to fetch the data using while loop in PHP
While loop Statement.
While loop Statement.   How to Print Table In java using While Loop
The While keyword
The While keyword       While is a keyword defined in the java programming language. Keywords... programming language likewise the while keyword indicates the following
php array loop while
php array loop while  Using the php array while loop
Java while coding - Java Beginners
Java while coding  Java loop and function coding question? How can I... * 19; I'd to use a method (function) to do the computation I'd like... boolexit=true; do { BufferedReader br = new BufferedReader(new

Ads