Posts

Showing posts from August, 2017

Program in C to find out reverse of a number (Dirty Code)

// Program to find reverse of a number // 1234 => 4321 // 4 X 10^3 = 4000 + 3 X 10^2 = 4300 + 2 X 10^1 = 4320 + 1 X 10^0 = 4321 #include <stdio.h> #include <math.h> int main(int argc, char const *argv[]) { int n, t, num = 0, count = 0; printf("Enter some number: "); scanf("%d", &n); t = n; // It's Counting number of digits while (t > 0) { int rem = t % 10; // Last Digit count++; t /= 10; } count--; // Reverse Code while (n > 0) { int rem = n % 10; // Last Digit num += rem * pow(10, count--); n /= 10; } printf("Reverse is %d\n", num); return 0; }

Java Program to count number of characters, alphabets, digits, words and vowels in a paragraph

// Program to count number of characters, alphabets, // digits, words and vowels in a paragraph class CountInSentence { static int count(String paragraph) { return paragraph.length(); } static int countAlphabets(String paragraph) { int count = 0; for (int i = 0; i < paragraph.length(); i++) { char ch = paragraph.charAt(i); if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) count++; } return count; } static int countDigits(String paragraph) { int count = 0; for (int i = 0; i < paragraph.length(); i++) { char ch = paragraph.charAt(i); if (ch >= '0' && ch <= '9') count++; } return count; } static int countWords(String paragraph) { return paragraph.split(" ").length; } static int countVowels(String paragraph) { int count = 0; for (int i = 0; i < paragraph.length(); i++) { char ch ...

Programming in Java (BSBC-502) Syllabus, TLEP, Question-Answers Bank

Programming in Java (BSBC-502) Syllabus, TLEP, Question-Answers Bank can be found by following below links Syllabus   TLEP Question-Answers Bank

Find distance between two points on 2D surface

// 3. Find distance between two points on 2D surface // Length of a line class LineDistance { public static void main(String[] args) { // Point 1 (Starting point) int x1 = 10; int y1 = 20; // Point 2 (Ending Point) int x2 = 100; int y2 = 120; float distance = (float)Math.sqrt(Math.pow((y2 - y1), 2) + Math.pow((x2 - x1), 2)); System.out.println("Length of a line is " + distance); } }

Program to convert the temperature in degree fahrenheit to degree celcius

/**  * Program to convert the temperature in degree fahrenheit to degree celcius  */ public class Converter {     public static void main(String[] args) {         float degFah = 120.f;         float degCel = (degFah - 32) * (5.0f/9);         System.out.println("Temperature in degree Celcius is " + degCel);     } }