Posts

Showing posts with the label sample

Armstrong numbers

Image
An Armstrong(after Michael F. Armstrong ) number, also known as Narcissistic number or pluperfect digital invariant(PPDI) OR plus perfect number , is a number that is sum of its own digits each raised to the power of the number of digits. For example: If the number is 371. How to find this number is an Armstrong number. First check the number of digit in this number. There are 3 digit, so take 3 as power. Now,  3 3 =27 7 3 =343 1 3 = 1 27+343+1=371 1634 is Armstrong or not?

Number Palindrome or not

Image
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.   A program

Simple Java program to Swap values

Image
In this post, I would like to share two simple program which swap value stored in two variables. In the first program, uses an extra variable to perform swapping and in the second program there is no additional variable used. These two program uses two variable a and b to hold the values inserted by user. After processing the value in variables get replaced by each other. That is the value in a get replace by the value in b and the value in b get replaced by the value in a. For instance if user inserts 10 and 25 into the variable a and b respectively, after process the variable a will have 25 and b will have 10. To perform this operation, normally,we need an extra variable which holds the value in variable either the value in a or in b. If we store the value in a to the additional variable, say s, then we can replace a with b's value. Now, we have variable a

Inputting values in Java

Java uses Streams to perform I/O. Java I/O system links the streams to physical devices.For any I/O devices the bhaviour of stream is same. This means that the programmer does not need to specify difference between keyboard and monitor in coding . Java defines two types of streams. Byte streams Character streams Byte streams provide a convenient way to handle input or output of bytes, that is, when reading or writing binary data. In Java, Byte stream are defined using two classes InputStream and OutputStream . The two most important methods that are, defined by this class, used for reading and writing of byte are : read() and write() . Character streams provide a convenient way to handle input or output of characters. In Java, Character stream are defined using two classes: Reader and Writer . These classes handle