Posts

Showing posts from July, 2020

JAVA PROGRAM TO CHECK OR FIND THE WHETHER THE ENTERED STRINGS ARE EQUAL OR NOT

/* Created by IntelliJ IDEA. * Author: Gyanendra Yadav (Gyanendra011Yadav-coder) * Date: 7/28/2020 * Time: 3:35 PM * File: Lab3Task.java */ //Create a program in Java, to input the coupon code from a client. If the client's coupon code // matches your already agreed upon code, then print a message to the client. package lab3 ; // 1 Import the Scanner class from the java.util package. import java.util.Scanner ; public class Lab3Task { public static final String DISCOUNT_CODE = "CoVid19" ; public static void main (String[] args) { // 2 Create an object of the Scanner class named 'scannerObject'. Scanner scannerobject = new Scanner(System. in ) ; // 3 Input the discount code from the client and store it in a String variable named 'clientInputDiscountCode'. System. out .println( "PLEASE ENTER THE CODE:" ) ; String clientInputDiscountCode = scannerobject.nextLine() ; if (clientIn...

JAVA PROGRAM TO FIND OUT EVCEN-ODD NUMBERS IN AN ARRAY

import java.util.Scanner ; public class EvenOddArray { public static void main (String[] args){ Scanner scan = new Scanner(System. in ) ; System. out .println( "ENTER THE LENGTH OF AN ARRAY:" ) ; int n = scan.nextInt() ; System. out .println( "ENTER THE ARRAY:" ) ; int arr[] = new int [n] ; for ( int i= 0 ; i< n ; i++ ){ arr[i] = scan.nextInt() ; } System. out .println( "EVEN NUMBERS ARE:" ) ; for ( int i = 0 ; i<n ; i++){ // WE ARE NOW CHECKING EVEN ODD NUMBERS if (arr[i]% 2 == 0 ){ System. out .print(arr[i]+ " " ) ; } System. out .println() ; System. out .println( "ODD NUMBERS ARE:" ) ; for ( int j= 0 ; i< n ; i++){ if (arr[i] % 2 != 0 ){ System. out .print(arr[i]) ; } } }

POWER SOLVING IN JAVA

import java.util.Scanner ; public class xRaisePowery { public static void main (String[] args){ Scanner scan = new Scanner(System. in ) ; System. out .println( "ENTER THE BASE VALUE" ) ; int x = scan.nextInt() ; System. out .println( "ENTER THE POWER" ) ; int n = scan.nextInt() ; int sum= 1 ; //now, we will apply condition for calculating the powers for ( int i = 1 ; i<=n ; i++){ sum*=x ; } System. out .println( "THE SOLUTION IS :" +sum) ; } }

PROGRAM FOR CALCULATING "FABONACCI NUMBER" IN JAVA

import jdk.swing.interop.SwingInterOpUtils ; import java.util.Scanner ; public class fabonacciNumber { public static void main (String [] args){ Scanner Scan = new Scanner((System. in )) ; int a = 0 ; int b = 1 ; System. out .println( "ENTER THE NUMBER UPTO THAT YOU WNAT TO CONTINUE THIS SERIES" ) ; int n = Scan.nextInt() ; System. out .print( a + " " ) ; System. out .print(b + " " ) ; int sum ; for ( int i = 0 ; i<n- 2 ; i++){ sum = a+b ; System. out .print(sum+ " " ) ; a=b ; b=sum ; } } }

FACTORIAL PROGRAM IN JAVA

import java.util.Scanner ; public class factorialProgram { public static void main (String [] args){ Scanner scan = new Scanner(System. in ) ; System. out .println( "ENTER THE NUMBER TO CALCULATE THE FACTORIAL OF THE NUMBER" ) ; int sum = 1 ; int n = scan.nextInt() ; for ( int i = n ; i> 0 ; i-- ){ sum*=i ; } System. out .println( "THE FACTORIAL OF THA GIVEN NUMBER YOU ENTERED IS:" +sum) ; } }

PROGRAM OF CALCULATING INTERSECTION OF TWO ARRAYS

PROGRAM    FINDING    OUT INTERSECTION    OF   TWO  GIVEN   ARRAYS import java.lang.reflect.Array ; import java.util.Arrays ; public class IntersectionOfAnArrays { public static void main (String [] args){ int arr1[] ={ 4 , 1 , 5 , 2 , 3 , 9 } ; int arr2[] ={ 5 , 6 , 7 , 4 , 8 , 9 } ; // int[] arr3 = new int[10]; Arrays. sort (arr1) ; Arrays. sort (arr2) ; for ( int i = 0 ; i<arr1. length ; i++){ for ( int j = 0 ; j<arr2. length ; j++){ if (arr1[i]==arr2[j]){ System. out .print(arr1[i] + " " ) ; } } }

JAVA PROGRAM TO CREATE A DATABASE (SAMPLE PICTURE IS GIVEN)

THIS IS THE PROGRAM OF TAKING USERS INPUT import com.sun.source.doctree.SystemPropertyTree ; import jdk.swing.interop.SwingInterOpUtils ; import org.w3c.dom.ls.LSOutput ; import javax.swing.* ; import java.util.Scanner ; import java.util.function.BinaryOperator ; public class GlaStudentsDetailApplication { public static void main (String[] args){ int n ; int sum ; int rollsum ; boolean HostelChoice = true ; Scanner scan = new Scanner(System. in ) ; // WE ARE ADDING THIS TO GENERATE STUDENT ROLL NUMBER System. out .println( "ENTER THE NUMBER OF STUDENTS YOU HAVE ENTERED BEFORE THIS STUDENT:" ) ; int serialnumber = scan.nextInt() ; scan.nextLine() ; System. out .println( "ENTER THE NAME OF STUDENT:" ) ; String snam = scan.nextLine() ; System. out .println( "ENTER THE FATHER'S NAME OF STUDENT:" ) ; String fname = scan.nextLine() ; System. ou...

Java Program For Performing Sum Of Last Four Digits Of A Number

import java.util.Scanner ; public class sumOfLastFourDigitsOfRollNumber { public static void main (String [] args){ Scanner scan = new Scanner(System. in ) ; System. out .println( "ENTER YOUR ROLL NUMBER:" ): int n = scan.nextInt() ; // now we will assign our value to any other number, so that the value of that number can be change int temp =n ; int sum = 0 ; // we can chnage any number to string to calculate it's length for ( int i = String. valueOf (n).length() ; i> 4 ; i--){ int lastDigit = temp % 10 ; temp =temp / 10 ; sum +=lastDigit ; } System. out .println(sum) ; } } OR, import java.util.Scanner ; public class sumOfLastFourDigitsOfRollNumber { public static void main (String[] args) { Scanner scan = new Scanner(System. in ) ; System. out .println( "ENTER YOUR ROLL NUMBER:" ) ; int n = scan.nextInt() ; int co...