Posts

Showing posts from January, 2017

mathajax

Decimal to 8 bit binary conversion

The number system conversion from decimal into binary is carried out by arithmetic operators, modulus and divider. The conversion program has to be given a decimal value which must be in the range from 0 to 255 and it returns binary 8 bits as a result of the conversion. Decimal to binary 8 bits conversion - Steps Given a decimal value, decval and converts it into binary 8 bits modulus decval (the given decimal value) by 2, it returns a reminder ( 0 or 1) divide decval by 2, it returns a quotient the quotient becomes the decval and repeat step 1 to 3 for 8 times the reminders on each iteration is results binary 8 bits Decimal to binary 8 bits conversion - Example Given decimal value = 143 ,convert it into binary 8 bits divide the decimal value by 2 returns a quotient and reminder, ...

Java program Sum and Average

The program is to finds sum and average or mean value from given N integers value . The input N integers are read from user via keyboard and used to calculate sum and average values. Example - given inputs N=5 and integers [2 5 8 12 6] sum = 2 + 5 + 8 + 12 + 6 sum = 33 average or mean = 33/5 = 6.6 pseudocode - Sum and Average Read N integers and store it into a array variable "intary" set sum=0,average=0 For i=0 to N-1   sum = sum + intary[i] End For average= sum / N print sum,average Java program - Sum and Average The Java program reads N input integers from user through BufferedReader connected with keyboard and calculate sum and average value of these inputs and returns sum and average value as results of the inputs. import java.io.BufferedReader; import java.io.IOException; import ja...

Java program Sum of Array Integers

Image
The java program find sum of  integers.       Pseudocode of sum of integer  set sum =0 Read an integer N initialize integer array size of N for n= 0  to N-1       Read an integer data      store data into array end for      for each E  in  array      sum = sum + E end each print sum Java keywords and objects usage in the program BufferedReader class object : provides stream mechanism to read inputs from user/keyboard Integer class object : converts string object into java primitive datatype int for-loop :- repeats reading inputs from user upto N times for-each  : to read element from array in sequential order  import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SumofArrayNumber { public static void main(String[] args) throws IOException   ...

Java program Fibonacci series

The successive numbers are generated from its previous two state numbers in the series is called Fibonacci series. Initially, the series has first number =0 and second number =1 and third successive number is generated by summing first and second number in the series. Initial Fibonacci series F has = {0,1} and successive elements are 3rd element = 0+1 =2 F = {0,1,2} 4th element = 1+2 =3 F = {0,1,2,3} 5th element = 2+3 =5 F = {0,1,2,3,5} Pseudocode - Fibonacci series to positive integer N Read integer N set variable cF=0, pF=1 Do print cF cF= cF + pF pF=cF-pF while cF Java Program - Fibonacci series The Java program generates Fibonacci series of numbers upto given integer N. import java.io.BufferedReader; import java.io.IOException; import ...

Java program Factorial Number

A result of series of multiplication from 1 to factorial F is called factorial number F Factorial Number - Example for example, a factorial number denoted by 5! (postfix exclamation symbol with digits) find equivalent decimal value for given a factorial number 5! 5! = 1 x 2 x 3 x 4 x 5 5! = 120 Factorial Number - Pseudocode Read a positive integer F set sf = 1 For n= 2 to F sf = sf * n End for print sf Factorial number - Java code The Java program finds factorial value for a number . The program reads a positive integer from user while running and returns factorial value as result of the it. import java.io.IOException; import java.util.Scanner; public class Factorial { public static void main(String[] args) throws IOException { ...

Java program Biggest number among N Integers

In order to f ind biggest number from unordered (not sorted) set of N numbers , a sequential search mechanism used, in which search starts from zero index to N-1 index. A Biggest number from array numbers - Pseudocode Read a integer N initialize memory array of N element Read integers and store into an array set biggest = 0; for n=0 to N check array[n] > biggest , set biggest = array[n] end for print biggest A Biggest number from array of numbers - Java program The Java program read N integers from user via keyboard and stored on an array. It has a for-loop to start sequential search to find a biggest number from this array of numbers . import java.io.IOException; import java.util.Scanner; public class BiggestAmongN { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); System.out.println( "Enter Number of Eleme...

Java Stream Input using BifferedReader

Add two numbers The java code add two numbers which are given as input to the code. The buffered reader object instance initialized to read the inputs from keyword. package cljavabasics; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; public class StreamInput { public static void main(String[] args) throws IOException { InputStreamReader dis = new InputStreamReader ( System.in ); BufferedReader br = new BufferedReader(dis); System.out.println( "Sum of Two Numbersn" ); System.out.println( "Enter first value" ); String arg1 =br.readLine(); int a = Integer.parseInt(arg1); System.out.println( "Enter second value" ); String arg2 =br.readLine(); int b = Integer.parseInt(arg2); int c= a+b; System.out.println( "ans : " + c ); } } Output Sum of Two Numbers Enter first value 30...

Java program Biggest Among 3 Numbers

The Java program finds a biggest number among 3 given numbers which are read by BufferedReader object wrapped of System.in (keyboard) object. While the Java program is running, Three inputs (data) read from keyboard as string object.The string inputs is converted into primitive integer datatype using a function, Integer.parseInt and stored these values into the variables. Biggest among 3 numbers - Pseudocode Read three input integers Stored these on int variables A,B and C IF A > B and A > C , then print "A is Biggest" IF B>C , then print "B is Biggest" ELSE , print "C is Biggest" Biggest among 3 numbers - Java Programming code The Java program finds biggest number from given 3 numbers which are read from keyboard using BufferedReader object. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Bigge...

Java CommandLine Argument

Image
It explains how to read arguments from commandline and how to use it in adding two numbers program. CommandLine Argument The inputs passed along with the program execution start up command are called commandline aruguments example - java CommandArgs 10 20 java - interpreter start executing a program CommandArgs - It is program need to be executed by the interpreter. 10 20 - These are commandline arguments passed to the program. A main function of the program receives these commandline arguments as a string array parameter. CommandLine Arguments - Java program The java program reads two inputs from command line, sum it and prints the result. public class CommandArgs { public static void main(String[] args) { int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); int c = a+b; System.out.println( " Sum of Two numbers :"...