10/08/2018

Java Program to Print Even Numbers in Upper Triangular and Odd Numbers in Lower Triangular in a Matrix

How to print an Even Numbers in Upper Triangular of a matrix and Odd Numbers in Lower Triangular of a Matrix and top-left to bottom-right diagonal should be zero. In this programming problem, we have to perform multiple tasks, we need to implement a multiple logic Here is the list of the task we have to perform while solving this problem.


This below pic explain everything in a simple language. See this image carefully you will get all the picture of the pattern problem in Java language. You can see that I have colored all three part for clarifying the problem in an easy way, Here you can see that the Upper Triangular with red color and Lower triangular with Blue color and a diagonal with Green color. So Now we got the problem we have to now find the solution by applying the above 3 programming logic. Before starting let again take a look in a simple way.


If the number value is 6 then we got we got a this output: 

0        2         4         6       8       10
1        0        12      16      18      20
3        5        0        22      24      26
7        11      13      0        28      30
17      19      23      29      0        32
31      37      41      43      47      0

Now upper triangular with even number line by line and with zero diagonal

0       2       4        6       8       10
         0       12      16     18      20
                  0        22     24      26
                            0       28      30
                                     0        32
                                                0

Now Lower triangular with odd number line by line and with zero diagonal

0
1       0
3       5       0
7       11      13      0
17      19      23      29      0
31      37      41      43      47      0

Here is a complete solution up to 18 digit number, this program can go up to any number of for better viewing output in a console screen I suggest use only up to 15 number. You can increase a limit by updating the value of an array(Increase the size of an array).

Solution to Print Even Numbers in Upper Triangular and Odd Numbers in Lower Triangular


import java.util.Scanner;
import java.util.Arrays;
class DiagonalEvenOdd
{
public static void main(String[] args)
{
Scanner sc =new Scanner(System.in);

System.out.print("Enter the Value Between 1-15\n\n");
System.out.print("Enter the Number: ");
int number=sc.nextInt();
pattern(number);
}
public static void pattern(int number)
{
int row=number;
int column=number;
int evenNum=2, primeNum=1;
int h=0, i=0, j=0, y=0, count=0;

int[] tempArr=null;
int[][] arr=new int[row][column];

for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
if(i==j)
{
arr[i][j]=0;
}
if(j>i)
{
if(evenNum==14)
{
evenNum+=2;
}
arr[i][j]=evenNum;
evenNum+=2;
}
if(j<i)
{
tempArr=new int[500];
y=0;
for(int p=1;p<=1000;p++)
{
count=0;
for(int q=1;q<=1000;q++)
{
if(p%q==0)
{
count++;
}
}

if(count<=2)
{
if(p==2)
{
continue;
}
tempArr[y]=p;
y++;
}
}
arr[i][j]=tempArr[h];
h++;
}
}
}

System.out.print("\n");

for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
}
}

Output:


Even Numbers in Upper Triangular and Odd Numbers in Lower Triangular
Read More »

10/02/2018

7 Ways How IOT May Impact Mobile App Development Process

IoT or "Internet of Things" refers to a network of devices or objects incorporating embedded technology that enables them to communicate with each other, even at far off distances. The connectivity can happen between innumerable devices like smoke alarms, appliances, light fixtures, and more. The technology can be used for smart gadgets, which can be controlled and accessed from a remote location.

Table of Content


  1. Picture of IOT
  2. Facilitates Interaction Between Devices 
  3. Enhanced Focus
  4. Increased App Security
  5. Encourages Specialization
  6. Brings Advancement
  7. Remote Accessibility
  8. Enhanced Flexibility

Just like the way it touches numerous industry verticals, there has been an innovation of IOT Development, which is the newest mobile app development process. If you want to know the various ways IOT can impact your mobile development process then here know the top 7 among all.

1.Facilitates Interaction Between Devices


IOT facilitates interactivity of devices thereby making it easier for the app developers as well as users to manage various tasks. The app developers are able to develop apps with fewer efforts and are also able to offer more innovative and user-friendly solutions.

2.Enhanced Focus


Previously, IOT development focused on developing applications with a user-friendly interface. But with the introduction of IOT, the emphasis is now on establishing an efficient integration between the sensors or devices and applications.

3.Increased App Security


The internet enabled gadgets to use user’s data, and there is a possibility that such devices may pass sensitive information to cybercriminals. IOT apps are safer and secure for the users, and hence, mobile app developers are expected to use IOT for application development.

4.Encourages Specialization


Internet of Things is a unique concept and needs specialization to be implemented in an appropriate way. IOT specific apps need additional skills, and the mobile developers need to develop such skills to remain competitive.

5.Brings Advancement


The futuristic IOT development process needs to offer support to the linked devices. If your mobile apps do not support IOT, then they will be at risk of not meeting the market expectations. It is essential that the developers create apps that are adaptable to smart linked devices.

6.Remote Accessibility


The IOT based gadgets can be controlled conveniently with the smart devices from anywhere. This implies developers need to generate apps that allow accessibility from various locations. This will give freedom to the users from dependence on location.

7.Enhanced Flexibility


IOT let developers create apps with flexible accessibility. It offers you an online functionality, though for a limited purpose. It allows accessing the mobile app via a smartphone on 24 x 7 from any part of the world to control and monitor the connected devices.

IOT is rapidly transforming the world, as already known. Smartphones have generated a lasting revolution in their own zones. The power of IoT is incomparable and hence, it is no more an option to consider IOT development. Rather, it has become a must for every enterprise or developer to create mobile apps embedded with IOT technology.

Hence, if you want to succeed in your business, then it is of utmost importance to find out a way where IOT can fit well into your business, no matter what size.

Author Bio - 


Kavya Gajjar is a Marketing Manager at AIS Technolabs which is Web design and Development Company, helping global businesses to grow by Ios App Development Services. I would love to share thoughts on  Social Media Marketing Services and Game Design Development etc.  For More:

LinkedIn: https://www.linkedin.com/company/ais-technolabs
Twitter: https://twitter.com/aistechnolabs
Facebook: https://www.facebook.com/aistechnolabs
Google+: https://plus.google.com/+AisTechnolabs
Read More »

9/21/2018

How to Achieve Abstraction in Java Programming

By following the below method you can easily achieve Abstraction in Java. In Java programming, a class defined with the abstract keyword is said to be an abstract class. It can use both abstract and non-abstract methods within the body. If you have just marked your presence in the developing zone, you can join the Java Certification Course which will help you to understand the core basics of Java programming with real-world application development. Before jumping directly to the abstract class of Java, let’s explore the abstraction process first. Let discuss how we to achieve Abstraction in Java language.

abstraction in oop java

What is the Abstraction exactly? 


In abstraction, we only show functionalities to a user by hiding the implementation and other details. Or, you can say displaying only useful information and hiding internal details. Let’s understand this with the help of an example, On your mobile phone, you set alarms without even knowing its internal functionalities like how it works.

Abstraction allows you to concentrate on objects work rather than explaining how it does.

Ways to Achieve to Abstraction in Java:


In Java, Abstraction can be achieved in two ways:

  1. By using abstract class
  2. By using interface

The interface helps you to achieve 100 percent abstraction.

Abstract Class: 

An abstract class is declared with the abstract keyword. It can leverage both abstract and non-abstract methods in it. An abstract class is extended and all its methods are implemented. Always remember a few rules before defining an abstract class:

  1. It must be declared by abstract keyword. 
  2. It comprised of both abstract and non-abstract methods. 
  3. It can include constructors as well as static methods. 
  4. It includes final methods which will not allow subclasses to alter the body methods. 

Declaration: 

abstract class X { }

Abstract Methods: 

The methods which are defined with the abstract keyword without any implementation are called as the abstract method. E.g.,

abstract void sayName(); //without method body

Real-world Example of Abstract Class:


Let’s understand the concept of an Abstract class and methods with the help of an example. Here I’m defining an abstract class named office with abstract method salary. The implementation of office class is provided by the emp and othworkers classes.

For end users- these implementation classes will be hidden. The factory mehtod (it returns the class instance) will provide the implementation class object. In this program, on creating the othworkers class instance, salary() method will be invoked.

abstract class office
{
abstract void salary();
}
class emp extends office{
void salary() {
System.out.println(“salaried employees”); }
class othworkers extends office{
void salary() {
System.out.println(“salaried workers”);
}
class AbstractionCheck
{
public static void main(String args[]){
office w=new otheworkers(); //object provided through method
w.salary();
}
}

In the above example the implementation will be unknown for end users and the methods will be called by user. The output of the program will be- salaried workers.

Another Example of Abstraction Achieved by Interface: 


Implementation of the interface can also be achieved by the abstract class. All the methods are overridden in such scenarios.

interface X{
void p();
void q();
void r();
}

abstract class Y implements X{

public void r(){
System.out.println(“Hello Its r”);
}

class S extends Y{
public void p(){
System.out.println(“Hi its p”);
}
public void q(){
System.out.println(“Hi its q”);
}
public void r(){
System.out.println(“Hi its r”);
}

class Check{
public static void main(String args[]){
X obj=new S();
obj.p();
obj.q();
obj.r();
}
}

Output#

Hi its p
Hi its q
Hi its r

Thus, we can see that abstraction can be achieved with the help of abstract classes as well as the interface. With abstraction class, you can create transparency of 0 to 100 percent while interface allows you to achieve 100% abstraction. 
Read More »

9/08/2018

Data Types in JavaScript with Examples

Primitive Data Types in JavaScript with Examples and full code in JS. When we talk about any language like C, C++, and Java, the most basic and most important characteristics of that is the set of data types of that language. Javascript support maximum 6 types of primitive data types which are Boolean, Null, Undefined, Number, String, and Symbol (new in ECMAScript 6), But we are focusing only 3 types of mainly using data types in javascript. JavaScript mainly focus on three primitive data types are–

  1. Numbers
  2. Strings
  3. Boolean

So What we are going to learn in this article, Here is a list of a content that we are going to learn in this Javascript datatypes article.

Index of Content


  • Picture of an Article
  • The concept of Data Types in JS
    1. Dynamic
    2. when number values added to a string
  • Data types in Javascript
    1. Numbers
    2. Strings
    3. Boolean
    4. Null
    5. Undefined
  • Examples of Data Types in Javascript
  • Javascript Array
  • Javascript objects
  • The typeof Operator
  • About Author

Javascript Data types with list of datatypes used in JS with Logo

Here, JavaScript also supports composite data type, is an object. An object is a collection of values like numbers, string, objects. JavaScript support dual nature of objects:

  1. JavaScript Object can represent an unordered collection of named values.
  2. And ordered a collection of numbered values. Like values are indexed with numeric values.

JavaScript Concept of Data Types:


Before working with data types one should know the behavior of Data Types. We assume that you already know the How statement Execute in JS.

i) Data types in JavaScript are Dynamic:

Data Types in JavaScript are dynamic means we define a variable once and that can hold different data type values. Like if we have a variable x then it can contain a numeric value and also a string value.

Example:

<!DOCTYPE html>
<html>
<body>
<p>Dynamic data types</p>
<p id="DynamicData"></p>


<script>
var x;             
x = 5;             
x = "Programming With Basics"; 
document.getElementById("DynamicData").innerHTML = x;
</script>
</body>
</html>

Here we define x and provide an integer value and again the same variable is provided string value. Now the value of x is string value then the result is “Programming With Basics”.

ii) when number values added to a string:

When a numeric value added to the string. JavaScript has a facility to handle this situation. Automatically it assumes int value is a string and append it with a string value.

Example:

<!DOCTYPE html>
<html>
<body>
<p>adding number and string</p>
<p id="DataTypeDemo"></p>
<script>
var AddNumAndString = 26 + "Programming with basics";
document.getElementById("DataTypeDemo").innerHTML = AddNumAndString;
</script>

</body>
</html>Now we see it didn’t gives error. Result will be 26Programming with basics.

Let’s define Data Types in Brief:

1. Strings Datatypes in JS:


The string is a series or collection of Characters.

Ex: “Programming with basics”

Also, the string can be defined in single quotes. We can use a string with conditions statements for example If, If-Else, and Switch statements.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>Strings in JavaScript</h2>
<p id="StringsInJS"></p>
<script>
var OurSite = "Programming With Basics";
var OurTutorial = 'DataTypes';
document.getElementById("StringsInJS").innerHTML =OurSite + ":" + OurTutorial;
</script>
</body>
</html>

2. Numbers in Javascript:


The numeric data is all digit values including decimal values, like 29, 105.98 etc. In JavaScript there are no integer or floating point values, JavaScript treats all numbers as floating point values.

Example:

<!DOCTYPE html>
<html>
<body>
<h>Numbers</h>
<p id="Numbers"></p>
<script>
var a = 10;
var b = 11;
var c = 12;
document.getElementById("Numbers").innerHTML =a + "<br>" + b + "<br>" + c;
</script>
</body>
</html>

3. JavaScript Booleans:


Boolean data types have two values only, either true or false.

Ex:  var x=true;
        var x=false;

Example:

<!DOCTYPE html>
<html>
<body>
<h>Boolean Demo</h>
<p id="BooleanDemo"></p>
<script>
var a = 10;
var b = 10;
var c = 15;
var x;
if(a==b||b==c)
{
x=true;
}
else
{
x=false;
}
document.getElementById("BooleanDemo").innerHTML =x;
</script>
</body>
</html

JavaScript Arrays:

JavaScript arrays are defined within square brackets, and the items within brackets are separated by a comma. As we defined earlier array based on numeric values, its index starts from 0.

Ex: We defined an array of all we have in our blog:
Var OurSite = [“C”, ”C++”, ”Java”, ”JS”, ”Hackerrank”];
Here C is at 0 indexes, C++ at index 1 and so on.

Example:

<!DOCTYPE html>
<html>
<body>
<h>Arrays in JavaScript</h>
<p id="Array"></p>
<script>
var oursite = ["C", "C++", "JavaScript", "Java"];
var text = "";
var i;
for (i = 0; i < oursite.length; i++) {
    text += oursite[i] + "<br>";
}
document.getElementById("Array").innerHTML = text;
</script>
</body>
</html>

JavaScript Objects:

Objects are key: value pairs, separated by a comma, are written inside curly brackets.

Ex:  var book = {Name:“JavaScript”, Pages:500, Price=400 }

Example:

<!DOCTYPE html>
<html>
<body>
<h>JavaScript Objects</h>
<p id="demo"></p>
<script>
var Book = {
    Name : "John",   
    Price  : 500,
    Pages : 400 
};
document.getElementById("demo").innerHTML =
Book.Name + " has " + Book.Price + " with no of pages" + Book.Pages;
</script>
</body>
</html>

4. Undefined in Javascript:


A variable without a value, has value undefined.
<!DOCTYPE html>
<html>
<body>
<h>Undefined Data Types</h>
<p id="undefineddemo"></p>
<script>
var x;
document.getElementById("undefineddemo").innerHTML =x;
</script>
</body>
</html>

5. Null in Javascript:


Null means no value. If we want to assign a null value to a variable.
Var a = null;

Know More: List of All Events in JS

The typeof Operator

typeof operator finds the data type of a variable.

Example:

<!DOCTYPE html>
<html>
<body>
<h> typeof operator <h>

<p id="demo"></p>

<script>
var x= 5;
var y ="PWB"
var z=null;
var k=undefined ;
document.getElementById("demo").innerHTML =
typeof x + "<br>" +
typeof y + "<br>" +
typeof z + "<br>" +
typeof k;
</script>
</body>
</html>

Result :

number
string
object
undefined

Here we observe that typeof returns number for a numeric variable, string for a string variable. Undefined for undefined value variable. But returned Object for null type, this will be a bug of JavaScript. The only difference between null and undefined is their data types, either their working behavior is the same.

Read More: For Loop in Javascript.

About Author


Data types in Javascript, this in-depth article is written by Suman Yadav.  She already wrote an article on Functions, What are a Functions in JS. You can also write to us, Submit your article and be a member of our A Programming Solutions Blog. Join us by sending a well-written article for more information visit Write for Us.
Read More »