HelpMeOutAlways: Java
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Saturday, March 2, 2019

Logic Gates Program In Java(Project)
March 02, 20190 Comments

Source Code



import java.util.Scanner;
//=====================================================================================================================
class star{
      public void star(){
        for(int i=1;i<=50;i++){
            System.out.print("*");
        }
    }
}
class OrGate extends star{
    int or1,or2;

    public void getSet(){
        Scanner Sc=new Scanner(System.in);
     
        System.out.println("\nEnter your Two numbers(either(1/0))\n");
        or1=Sc.nextInt();
        or2=Sc.nextInt();
    }
    public void or(){
        if((or1==0)&&(or2==0)){
            System.out.println("Your output is:");
            System.out.println("0");
        }
        else{
            System.out.println("Your Output is:");
            System.out.println("1");
        }
    }
}
//======================================================================
class AndGate extends star{
    int and1,and2;
 
    public void getSet(){
        Scanner Sc=new Scanner(System.in);
     
        System.out.println("\nEnter your Two numbers(either(1/0))\n");
        and1=Sc.nextInt();
        and2=Sc.nextInt();
    }
    public void and(){
        if((and1==1)&&(and2==1)){
            System.out.println("Your output is:");
            System.out.println("1");
        }
        else{
            System.out.println("Your Output is:");
            System.out.println("0");
        }
    }
}




//======================================================================

class NotGate extends star{
    int not1,not2;
 
    public void getSet(){
        Scanner Sc=new Scanner(System.in);
     
        System.out.println("\nEnter your one numbers(either(1/0))\n");
        not1=Sc.nextInt();
        //not2=Sc.nextInt();
    }
    public void or(){
        if(not1==0){
            System.out.println("Your output is:");
            System.out.println("1");
        }
        else if(not1==1){
            System.out.println("Your Output is:");
            System.out.println("0");
        }
        else{
            System.out.println("Invalid Input");
        }
    }
}

//======================================================================
class NorGate extends star{
    int nor1,nor2;
 
    public void getSet(){
        Scanner Sc=new Scanner(System.in);
     
        System.out.println("\nEnter your Two numbers(either(1/0))\n");
        nor1=Sc.nextInt();
        nor2=Sc.nextInt();
    }
    public void nor(){
        if((nor1==0)&&(nor2==0)){
            System.out.println("Your output is:");
            System.out.println("1");
        }
        else {
            System.out.println("Your Output is:");
            System.out.println("0");
        }
     
    }
}

//======================================================================
class NandGate extends star{
    int nand1,nand2;
 
    public void getSet(){
        Scanner Sc=new Scanner(System.in);
     
        System.out.println("\nEnter your Two numbers(either(1/0))\n");
        nand1=Sc.nextInt();
        nand2=Sc.nextInt();
    }
    public void nand(){
        if((nand1==1)&&(nand2==1)){
            System.out.println("Your output is:");
            System.out.println("0");
        }
        else {
            System.out.println("Your Output is:");
            System.out.println("1");
        }
     
    }
}

//======================================================================
class XorGate extends star{
    int xor1,xor2;
 
    public void getSet(){
        Scanner Sc=new Scanner(System.in);
     
        System.out.println("\nEnter your Two numbers(either(1/0))\n");
        xor1=Sc.nextInt();
        xor2=Sc.nextInt();
    }
    public void xor(){
        if(xor1==xor2){
            System.out.println("Your Output is");
            System.out.println("0");
         
        }
        else if(xor1==xor2){
             System.out.println("Your Output is");
         System.out.println("0");
        }
        else{
            System.out.println("1");

        }
    }
}
//======================================================================
class XnorGate extends star{
    int xnor1,xnor2;
 
    public void getSet(){
        Scanner Sc=new Scanner(System.in);
     
        System.out.println("\nEnter your Two numbers(either(1/0))\n");
        xnor1=Sc.nextInt();
        xnor2=Sc.nextInt();
    }
    public void xnor(){
        if((xnor1==1)&&(xnor2==1)){
            System.out.println("Your output is:");
            System.out.println("1");
        }
        else if((xnor1==0)&&(xnor2==0)) {
            System.out.println("Your Output is:");
            System.out.println("1");
        }
        else{
            System.out.println("0");
        }
     
    }
}
//======================================================================
public class Main{
    public static void main(String args[]){
 System.out.println("Note: You have to give input either 1 or 0");     
System.out.println("1. OR Gate");
System.out.println("2.AND Gate");
System.out.println("3. NOT Gate");
System.out.println("4. NOR Gate");
System.out.println("5. NAND Gate");
System.out.println("6. XOR Gate");
System.out.println("7. XNOR Gate");
System.out.println("Which operation would you like to perform:");     
int menu;
 Scanner In=new Scanner(System.in);
 menu=In.nextInt();
 
    switch(menu){
    case 1:
       
         OrGate obj1=new OrGate();
         obj1.star();
         System.out.println("\nOR Gate\n");
         obj1.star();
        obj1.getSet();
        obj1.or();
     
       break;
     case 2:
         AndGate obj2=new AndGate();
         obj2.star();
         System.out.println("\nAND Gate\n");
         obj2.star();
        obj2.getSet();
        obj2.and();
     
        break;
    case 3:
        NotGate obj3=new NotGate();
        obj3.star();
         System.out.println("\n NOT Gate\n");
         obj3.star();
        obj3.getSet();
        obj3.or();
        break;
     
     
    case 4:
        NorGate obj4=new NorGate();
        obj4.star();
         System.out.println("\nNOR Gate\n");
         obj4.star();
        obj4.getSet();
        obj4.nor();
        break;
    case 5:
        NandGate obj5=new NandGate();
        obj5.getSet();
        obj5.nand();
     
        break;
    case 6:
         XorGate obj6=new XorGate();
         obj6.star();
         System.out.println("\n XOR Gate\n");
         obj6.star();
        obj6.getSet();
        obj6.xor();
     
        break;
    case 7:
         XnorGate obj7=new XnorGate();
         obj7.star();
         System.out.println("\n XNOR Gate\n");
         obj7.star();
        obj7.getSet();
        obj7.xnor();
     
        break;
    default:
    System.out.println("Invalid Input");
     
     
    }
    }

 
    }

Output

logic gate program

logic gates

 

Reading Time:

Saturday, February 23, 2019

Program Swapping Two Numbers In Java Without 3rd Variable
February 23, 20190 Comments

Source Code

import java.util.Scanner;
class InterChangeNo{
    
    public void swap(){
        int a, b;
      System.out.println("Enter the value of a and b:");
      Scanner in = new Scanner(System.in);
 
      a = in.nextInt();
      b = in.nextInt();
 
      System.out.println("Before Swapping\nx = "+a+"\ny = "+b);
 
      a = a + b;
      b = a - b;
      a = a - b;
 
      System.out.println("After Swapping\nx = "+a+"\ny = "+b);
    }
    
}
 
class Main
{
   public static void main(String args[])
   {
      InterChangeNo obj=new InterChangeNo();
      obj.swap();
   }
}

Output

Java program

Reading Time:
Program Swapping Two Numbers In Java With 3rd Variable
February 23, 20190 Comments

Source Code

import java.util.Scanner;
 class InterchangeNo{
 
  public void swap(){
   int x, y, temp;
      System.out.println("Enter any two numbers for swaping them:");
      Scanner in = new Scanner(System.in);
   
      x = in.nextInt();
      y = in.nextInt();
   
      System.out.println("Before Swapping it was\nx = "+x+"\ny = "+y);
   
      temp = x;
      x = y;
      y = temp;
   
      System.out.println("After Swapping it is\nx = "+x+"\ny = "+y); 
  }
 }
class Main{
   public static void main(String args[]){
   InterchangeNo obj=new InterchangeNo();
   obj.swap();
   
   }
}

Output

java program

Reading Time:

Tuesday, February 19, 2019

A Program That Take String As Input And Gives it's Reverse Without Using Any Built-In-Function(JAVA)
February 19, 20190 Comments

Source Code

import java.util.Scanner;

class ReverseString{
    public void stringReverse(){
    String original, reverse = "";
      Scanner in = new Scanner(System.in);

      System.out.println("Enter a string to reverse");
      original = in.nextLine();

      int length = original.length();

      for ( int i = length - 1 ; i >= 0 ; i-- )
         reverse = reverse + original.charAt(i);

      System.out.println("Reverse of entered string is: "+reverse);
    }
}
 class Main{
   public static void main(String args[]){
     ReverseString obj= new ReverseString();
     obj.stringReverse();
   }
}

Output

java string program

Reading Time:
A Program That Takes String As an Input And Prints It's Reverse(Java)
February 19, 20190 Comments

Source Code

import java.util.Scanner;
  class ReverseString{
   
      public void stringReverse(){
    System.out.println("Enter string to reverse:");
     
        Scanner read = new Scanner(System.in);
        String str = read.nextLine();
     
        StringBuilder sb = new StringBuilder();
     
        for(int i = str.length() - 1; i >= 0; i--)
        {
            sb.append(str.charAt(i));
        }
     
        System.out.println("Reversed string is:");
        System.out.println(sb.toString());
      }
  }
   
    class Main{
    public static void main(String[] args)
    {
    ReverseString obj=new ReverseString();
    obj.stringReverse();
    }
}


Output

java program string revese

Reading Time:
A Program That Takes Input And Tell it's Factorial without Using Any Loop(Java Program)
February 19, 20190 Comments

Source Code

import java.util.Scanner;
class FactorialRecursion{
    public void fact(){

      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter the number:");

      int num = scanner.nextInt();

      int factorial = fact(num);
      System.out.println("Factorial of entered number is: "+factorial);
   }
   static int fact(int n)
   {
       int output;
       if(n==1){
         return 1;
       }

       output = fact(n-1)* n;
       return output;
   }
}
class Main{
   public static void main(String args[]){
     FactorialRecursion obj=new FactorialRecursion();
     obj.fact();
   }
}

Output

java program

Reading Time:
A Program That Takes Number As Input And Prints It's Factorial
February 19, 20191 Comments

Source code


import java.util.Scanner;

class FactorialProgram
{

public void fact ()
  {
 
int i, fact = 1;
 
Scanner Sc = new Scanner (System.in);
 
System.out.println ("Enter any number to find it's Factorial");
 
int number = Sc.nextInt ();
 
for (i = 1; i <= number; i++)
      {

fact = fact * i;
   

}
 
System.out.println ("Factorial of " + number + " is: " + fact);

}


}

class Main{

public static void main (String args[]){
 
FactorialProgramobj = new FactorialProgram
();
 
obj.fact ();

}
}

Output

java program
Reading Time:

Wednesday, January 23, 2019

Simple program of Array Using Class and Method(Java)
January 23, 20190 Comments

Source Code

class MyPro{
      public void print(){
       int[ ] primes = {2, 3, 5, 7};
       
        for (int t: primes) {
            System.out.println(t);
        }
        }
}
public class Program {
    public static void main(String[] args) {
    
     MyPro obj=new MyPro();
     obj.print();
    }

}

 Output


#arrayprogramming #java #class #method
Reading Time:

Tuesday, August 21, 2018

A Simple Program To Write "F" In Java Using for Loop
August 21, 20180 Comments
Source Code

public class Program
{
public static void main(String[] args) {
    int h,i,j,k;
    for(h=1;h<=10;h++)// For First Rows (Horizontal line)
    System.out.print("*");
    for(i=1;i<=10;i++)  // For Column (Vertical line)
    System.out.println("*");
    for(j=1;j<=i;j++)   // for 3rd line(rows)
    System.out.print("*");
    for(k=1;k<=i;k++)  // for fourth line (column)
    System.out.println("*");

}
}

Output


java for loop

Reading Time:
Syntax of Java  ( First Program in Java) Simple Example
August 21, 20180 Comments
Source Code

public class Program //you can give any name to "class"
{
public static void main(String[] args) {
    
    System.out.println("Hello! java");
    // Note you have to write "S" capital in "System" 
    System.out.println("This is my First Program In Java");

}
}


Output
Reading Time:

Saturday, August 18, 2018

What is Java Programming Language?
August 18, 20180 Comments

Java Programming Language


Java is,


  • A high-Level Programming Language
  • A general-purpose Object-Oriented Language (Based on the concepts of "Objects") called OOP(Object-oriented Programming)
  • It is designed for Web/internet applications.
  • The name "Java" is basically derived from the Island of Indonesia Java and the people of Javanese speaks the Javanese language, which is a natural language.
  • Java is a platform independent language, which means once you have written a program in this language you will able to run this on different platforms. 
  • Java was designed by James Arthur Gosling (Canadian Computer Scientist).
  • It was developed by Sun MicroSystem( now owned by Oracle Corporation)
  • It first appeared on May 23, 1995; 23 years ago(2018).
  • It is used to develop Apps for Google's Android OS and also for Desktop Computers, such as anti-virus,  media players, web applications, Enterprise Applications(i.e Banking ) and etc.
    https://www.helpmeoutalways.com/
Reading Time:

@way2themes