Friday, August 5, 2016

How to input numbers and print it in ascending order without using arrays and lists

When you try to sort a set of numbers in ascending series you can do it in many different ways . Among them you can use bubblesort ,heap data structure etc . but right now this tutorial is about how to sort a set of numbers in ascending series without using arrays and lists . Here is the code :

package asc;


import java.util.Scanner;

public class Asc {

  
    public static void main(String[] args) {
        String lottery="";
         long digit;
         long closet;
         long sorted;
         long hero =10;
       Scanner plot = new Scanner(System.in);
       System.out.println("No of numbers");
        long num = plot.nextInt();
       
       for( long i = 1;i<=num;i++){
           System.out.println("enter "+i+" number");
            long st = plot.nextInt();
           String crate = String.valueOf(st);
           closet = crate.length();
           if(closet==1){
               hero=10;
               
           }
           else if(closet ==2){
               hero = 100;
           }else if (closet==3){
               hero =1000;
               
           }else if (closet== 4){
               hero = 10000;
           }else if(closet == 5){
               hero = 100000;
       }
           lottery = String.valueOf(st)+lottery;
               long number = Integer.parseInt(lottery);
             sorted = 0;
 long digits = hero;
 long sortedDigits = 1;
boolean first = true;

while (number > 0) {
     digit = number % hero;

    if (!first) {

         long tmp = sorted;
         long nep= 1;
        for ( long k = 0; k < sortedDigits; k++) {
            
             long tmpDigit = tmp % hero;
            if (digit >= tmpDigit) {
                sorted = sorted/nep*nep*hero + digit*nep + sorted % nep;
                break;
            } else if (k == sortedDigits-1) {
                sorted = digit * digits + sorted;
            }
            tmp /= hero;
            nep *= hero;
        }
        digits *= hero;
        sortedDigits += 1;
    } else {
        sorted = digit;
    }

    first = false;
    number = number / hero;
}
System.out.println(sorted);
        
       }
    
       


    }
    
}

now lets talk about how this works :

suppose you are given a number  486243      .How can you take out 3 which  is last number its simple . you do :

486243 % 10 or 486243 mod 10

to take out 4 you remove 3 by dividing 486243 by 10 and 

48624 % 10 or 48624 mod 10

but taking out is not enough you add it in ascending order by 

sorted = sorted/nep*nep*hero + digit*nep + sorted % nep;

and in this input number is in ascending order.





Wednesday, July 27, 2016

Program to reverse a string in qbasic with explanation


cls
input"enter the string to reverse";a$
for i = 1 to len(a$)
q$=mid$(a$,i,1)
m$=q$+m$
next i 
print m$
end

                    
len(a$)  = to return the number of characters from the string
mid$(a$,i,1) = to replace a string portion with another string .



program explanation :

the program is started with the input.
then the program goes to a loop which starts from 1 and ends with the length of input.
there is the use of mid$ . why? let me give you a example : if you input a string "closure" then loop is started from 1 to length of  closure i.e 7 and mid$ takes out :

loop count                                     string


1                      c
2                      l
3                      o
4                      s
5                      u
6                      r
7                      e

after that a new string variable is created which stores in given way

if a$="ram" then

1                      p$=r
2                      p$=a
3                      p$=m


m$ where m$ is a new string

m$=a$+m$ 
so that

count                 m$

1                      r 
2                      ar
3                      mar

loop is ended and m is printed. 




Monday, July 25, 2016

What is Ethical hacking



Ethical Hacking



Ethical Hacking
Ethical hacking is the computer and networking expert who is able to penetrate the computer system or network. There are two types of ethical hacker:



1.White Hat
These are the hackers who works on behalf of the computer system or network owners for the purpose of finding security vulnerabilities that a malicious hacker could potentially exploit.
2.Black Hat
These are the malicious hackers who hack the computer system or network for their own purpose.These are the illegal hackers.


These white hats and black hats are derived from the old western movies where the "good guy" always wear the white hat where as the "bad guy" always wear the black hat.



Why Ethical Hackers are needed (White Hat) ?
Ethical hackers are needed because they test the system and prevent the system owners fro getting hacked.For eg : Pro Hackerz were used to test the local advert system which made the server almost unhackable.


Nowadays every computer system or network are using ethical hackers to hack their own system and give them the chance to improve their mistakes.




How To Run Java Programs in Cmd



How To Run Java Programs In Cmd

So you are having problem in running java programs from cmd .This tutorial will be teaching you How To Run Java Programs In Cmd . Many of you may have faced problems like this image




This is the problem that is common to many of them . To fix it all you need to do is set up the path in environment variables.

Step 1 >> Go to contol panel

Step 2 >> Search for environment variables.




after you searched for environment variables just click Edit the system environment variable then a popup will appear like this.



Click on Environment Variables again there is new popup.where you would be able to see user variables for Your username. just below you would see New.. click there .

Set the variable name to : -- path
Set the variable value to:-- javac path generally C:\Program Files\Java\jdk1.8.0_45\bin


it may differ from mine. save it and congratulations now you can run java programs from cmd.

CHEERS




How to create a file downloader in Java


Create a console based file downloader in Java


This tutorial is all about creating a java based downloader . So lets get started

This program uses a URLConnection to download the contents from the file.

import java.io.*; import java.net.*; import java.util.Scanner; public class filesfromsite { public static void main(String[] args) { Scanner inp = new Scanner(System.in); InputStream in = null; FileOutputStream fout = null; URLConnection connection = null; System.out.println("enter url"); String ur=inp.next(); System.out.println("name to save"); String kur = inp.next(); try{ URL url = new URL(ur); connection = url.openConnection(); in = connection.getInputStream(); fout = new FileOutputStream(kur); int b; while(((b = in.read()) != -1 )){ fout.write(b); } }catch(IOException exc){ System.out.println("connection error;"+ exc); }finally{ try{ if(in!= null) in.close(); if(fout != null) fout.close(); } catch(IOException exc){ System.out.println("Error closing stream "+ exc); } } } }

Lets see how the program works . The first is an InputStream called in , second one is URLConnection called connection , the third one is fileoutputStream called fout . Scanner asks for user input for url ,then the name of file and stores in ur and kur correspondly . After user input the url is defined and is tried to be opened by URLconnection .Then InputStream gets everything in in that connection.to get the output FileOutputStream is used . Then int b is defined then b stores everything passed by inputstream and saves it to FileOutputStream. and after that everything is closed and the program is successful in downloading.

Note :

the program will run until the file is downloaded completely and you have to define extension by yourself. The downloaded file will be on the same directory where your program is .


How to create a graph of sine in qbasic

Sine is the trigonometrical function based on right angled triangle .  when we plot the value of sine in graph paper you will get the result as below . It is very easy to plot sine in graph paper .Taking a calculator and a graph paper is enough for that job . 


Now lets learn how to create the sine wave in the computer using qbasic . It is preety easy to create a sine wave in qbasic so lets get started

< Step 1 /> : create a loop

create a loop starting from 0 to 360 and define screen as we are playing with graphics . 

cls
screen 13
for i = o to 360
next i


< Step 2 /> : convert the numbers into radians and use the SIN function.


you have to convert numbers into radians as SIN function requires the angle argument to be in radians. the formula is :

                                              (x/180)*pie 
where x is angle and value of pie = 3.1415

so we can write like this :

cls
screen 13
for i = o to 360
x= sin((i/180)*3.1415)
next i

<Step 3/> : using pset function to draw it on screen.

the last thing is you use pset function to get it drawn on screen and it goes like this.

cls
screen 13
for i = o to 360
x= sin((i/180)*3.1415)
pset(i,(x*50)+50),4
next i

ok now lets look at pset . while using pset function x is multiplied and added with 50 . it is the way of defining the amplitude. if you set it to zero then you would just get a straight line so you have to define the amplitude.while using pset instead of i you can use (i/360)*320 because we used screen 13 and it is just 320 pixels whereas sine wave is 360 pixels .  

here is the final program :

cls
screen 13
for i = o to 360
x= sin((i/180)*3.1415)
pset((i/360)*320,(x*50)+50),4
next i