Sunday, 17 March 2019

How to Get First and Last word from String using Java

/* java program to get first and last word of a string */

class wordDisplay{
public static void main(String args[]){

String str = "Object Oriented Protramming" ;

//get first word
int firstSpacePosition = str.indexOf(" ");

String firstWord = str.substring(0,firstSpacePosition); // Object

//get last word

String lastWord = str.substring(str.lastIndexOf(" ")+1); //Programming

//print
System.out.println("first word : "+firstWord);
System.out.println("Last word: "+lastWord);
}
}

Saturday, 16 March 2019

java program to get first and last character of a string

/* java program to get first and last character of a string */

 class PositionDemo{
public static void main(String args[]){

String str = "123456789" ;

//get First character
char first = str.charAt(0);

//get Last character
char last = str.charAt(str.length()-1);  //get last character

System.out.println("First charcater : "+first);
System.out.println("Last charcter :"+last);

}
 }

Sunday, 4 November 2018

Code For add item in jcomboBox At Runtime : jcombobx tutorial



ADD Item in JcomboBox 

By using   addItem(String item)

For Example :

 jComboBox1.addItem(addValue);

where
jComboBox1 :  object of JComboBox
and
addValue  :  value which we want to insert into jcombobox



For Video Open Link :   ADD Item in JComboBox --video


Saturday, 27 October 2018

square root of number in java Example | sqrt() function in java

/* java program to find square root of a Number */
class MathDemo{
public static void main(String args[]){

// values for square root
double a = 144;
double b = 9;

//result of square root
System.out.println("\nSquare root of 144 is : "+Math.sqrt(a));
System.out.println("\n Squre root of 9 is : "+Math.sqrt(b));

}
}

o/p
Square root of 144 is :12
Square root of 9 is : 3

Friday, 26 October 2018

How to Convert Double To String in JAVA Example

/* JAVA Program of  Convert Double To String (Java Converion )*/

class ConversionDemo{
public static void main(String args[]){
        //method 1 using valueOf Method

double value = 222.02;
String str = String.valueOf(value); // converion
System.out.println("using valueOf Method :"+str);

// method 2 using toString method
double dval = 303.04

String str2 = Double.toString(dval); //converion
System.out.println("Conversion Using toString Method :"+str2);


}
}

Sunday, 21 October 2018

isalnum() function in C programming - ctype.h library function

/* write a C program to check Enter character is Alphanumeric or Not */

#include<stdio.h>
#include<conio.h>
#include<ctype.h> // library for islower function must require it
void main()
{
       char c;
       printf("Enter character : ");
       scanf("%c",&c);
     
       if(isalnum(c)==0)
           printf("Enter character is Not  alphanumeric character");
       else
          printf("Enter character is alphanumeric  character");
getch();

}

JTable Hide and Show in Java Swing