You are on page 1of 6

APILADO, JOHN ROBERT

DEET 2-1

import javax.swing.JOptionPane;

public class substringSmpl

public static void main (String[] args)

String input,str;

int start,end;

str = JOptionPane.showInputDialog ("Enter String:");

input =JOptionPane.showInputDialog ("Enter Start Index:");

start = Integer.parseInt (input);

input = JOptionPane.showInputDialog ("Enter Start Index:");

start = Integer.parseInt (input);

input = JOptionPane.showInputDialog ("Enter Number of Characters:");

end = Integer.parseInt (input);

JOptionPane.showMessageDialog (null,"The Sub-String is: " +


str.substring(start,end),"OUTPUT",JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}
APILADO, JOHN ROBERT
DEET 2-1
APILADO, JOHN ROBERT
DEET 2-1

public class StringSmpl

public static void main (String [] args)

String str = "Diploma in Electrical Engineering Technology";

System.out.println ("String : " + str);

System.out.println ("Length : " +

str.length());

System.out.println ("Upper Case : " +

str.toUpperCase());

System.out.println ("Letter on index 5 : " +

str.charAt(5));

System.out.println ("Index of letter n : " +

str.indexOf ('n'));

System.out.println ("Replace o with e : " +

str.replace ('o','e'));

}
APILADO, JOHN ROBERT
DEET 2-1
APILADO, JOHN ROBERT
DEET 2-1

import javax.swing.JOptionPane;

public class ArraySmpl

public static void main (String[] args)

String input;

int eleno, max;

int [] no = new int[5];

for (eleno = 0; eleno <= 4; eleno++)

input = JOptionPane.showInputDialog

("Enter Value for Element " + eleno + ":");

no[eleno] = Integer.parseInt(input);

max = no[0];

for (eleno = 0; eleno <= 4; eleno++)

if (no[eleno] > max)

max = no[eleno];

JOptionPane.showMessageDialog (null,"The Highest Number on Array is " +

max,"OUTPUT",JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}
APILADO, JOHN ROBERT
DEET 2-1

You might also like