Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners programes on do... while
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Amit
programes on do... while
3 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


  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

Advertisement
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... = num; //use to check at last time int check=0,remainder; while(num > 0
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      ...-while statement now. Here is the syntax: do { statement(s) } while (expression); Lets tweak an example of do-while loop
while and do while
while and do while  hello, What is the difference between a while statement and a do statement?   hello, A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do
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 loop
php do while loop  Difference between do while loop and simple loop in PHP
php do while example
php do while example  Simple example of do while loop in PHP
php do while syntax
php do while syntax  How to create a do while loop in php. What is the syntax
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
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
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
Class.forName will do while loading drivers
Class.forName will do while loading drivers  What Class.forName will do while loading drivers
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 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
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: do { statements; } while(condition
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
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); } }  
Do..While Loops
3.10.2. Do…While Loops The do...while statement always execute... the condition is true. Syntax do { code to be executed; } while (condition); e.g.... reaches to either 5 or less than 5. <?php $i=1; do { $i++; echo &ldquo
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
While and do-while
While and do-while      ... at do-while statement now. Here is the syntax: do { statement(s) } while (expression); Lets tweak an example of do-while loop
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...); long rem; while(num > 0){ rem = num % 10; num
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
Advertisements
 

 

 

DMCA.com