Sie sind auf Seite 1von 43

[Type the document title]

AKASH NAIR
6151

PRACTICAL-1: JAVA BASICS

1.Write a Java program that takes a number as input and prints its multiplication
table upto 10.

import java.util.*;

class testmul
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number");
int a=sc.nextInt();
for(int i=1;i<=10;i++)
{
System.out.println(a+ "*" +i + "=" +a*i);
}
}
}
Output-
[Type the document title]
AKASH NAIR
6151

2.Write a Java program to display the following pattern.


*****
****
***
**
*

class pat
{
public static void main(String[] args)
{
int n= 5;

for(int i=n;i>=1;--i)
{
for(int s=1;s<=n-i;++s)
{
System.out.print(" ");
}

for(int j=i;j<=2*i-1;++j)
{
System.out.print("* ");
}

for(int j=0;j<i-1;++j)
{
System.out.print("* ");
}

System.out.println();
}
}
}
Output-

3.Write a Java program to print the area and perimeter of a circle.

class testar
[Type the document title]
AKASH NAIR
6151

{
public static void main(String ar[])
{
int r=2;
double peri=2*3.14*r;
double area=3.14*r*r;
System.out.println("area is "+area);
System.out.println("perimeter is "+peri);
}
}
Output-


[Type the document title]
AKASH NAIR
6151

PRACTICAL-2 Use of Operators


1.Write a Java program to add two binary numbers.

import java.util.Scanner;
public class JavaExample
{
public static void main(String[] args)
{
long b1, b2;
int i = 0, carry = 0;
int[] sum = new int[10];
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first binary number: ");
b1 = scanner.nextLong();
System.out.print("Enter second binary number: ");
b2 = scanner.nextLong();
scanner.close();
while (b1 != 0 || b2 != 0)
{
sum[i++] = (int)((b1 % 10 + b2 % 10 + carry) % 2);
carry = (int)((b1 % 10 + b2 % 10 + carry) / 2);
b1 = b1 / 10;
b2 = b2 / 10;
}
if (carry != 0) {
sum[i++] = carry;
}
--i;
System.out.print("Output: ");
while (i >= 0) {
System.out.print(sum[i--]);
}
System.out.print("\n");
}
}
Output-

2.Write a java program to convert a decimal number to binary number and vice
versa.
[Type the document title]
AKASH NAIR
6151

Binary to Decimal-

import java.util.Scanner;
public class bintodec {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
long binaryNumber, decimalNumber = 0, j = 1, remainder;
System.out.print("Input a binary number: ");
binaryNumber = sc.nextLong();

while (binaryNumber != 0)
{
remainder = binaryNumber % 10;
decimalNumber = decimalNumber + remainder * j;
j = j * 2;
binaryNumber = binaryNumber / 10;
}
System.out.println("Decimal Number: " + decimalNumber);
}
}
Output-

Decimal to Binary-
import java.util.*;
class DectoBin
{
public static void main(String arg[])
{

Scanner sc=new Scanner(System.in);


System.out.println("Enter a decimal number");
int n=sc.nextInt();
int bin[]=new int[100];
int i = 0;
while(n > 0)
{
bin[i++] = n%2;
n = n/2;
}
System.out.print("Binary number is : ");
for(int j = i-1;j >= 0;j--)
[Type the document title]
AKASH NAIR
6151

{
System.out.print(bin[j]);
}
}
}
Output-

4.Write a program to reverse a string.

import java.util.*;
public class ReverseString
{
public static void main(String args[])
{
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 the string: " + reverse);
}
}
Output-
[Type the document title]
AKASH NAIR
6151

PRACTICAL-3: JAVA DATA TYPES


1.Write a Java program to count the letters, spaces, numbers and other characters of
an input string.

class hello
{
public static void main(String ar[])
{
String str=" HEllo";
System.out.println(str.toUpperCase());
[Type the document title]
AKASH NAIR
6151

System.out.println(str.toLowerCase());
System.out.println(str.length());
String s1=str.trim();
System.out.println("length after trimming"+s1.length());
System.out.println(str.charAt(3));
String s3=str.replace('H','T');
System.out.println("new value is"+s3);
int a=10;
String s2=String.valueOf(a);
System.out.println(s2+10);
String s4="SYITA";
String s5="SYITB";
System.out.println(s4.equals(s5));
System.out.println(s4.compareTo(s5));
}
}
Output-

2.Implement a java function that calculates the sum of digits for a given char array
consisting of the digits ‘0’ and ‘9’. The function should return the digit sum as a long
value.

import java.util.*;
class prac3B
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.print("Enter the any string: ");
String s=ob.nextLine();
[Type the document title]
AKASH NAIR
6151

count(s);
}
public static void count(String str)
{
int sum=0;
int d=0;
char ch[]=str.toCharArray();
for(int i=0;i<str.length();i++)
{
if(Character.isDigit(ch[i]))
{
sum+=Character.getNumericValue(ch[i]);
}
}
System.out.println("Your addtion is: "+sum);
}
}
Output-

3.Find the largest and smallest element from array.

public class LargestSmallest


{
public static void main(String[] args)
{
int a[] = new int[] { 23, 34, 13, 64, 72, 90, 10, 15, 9, 27 };
int min = a[0];
int max = a[0];
for (int i = 1; i < a.length; i++)
{
if (a[i] > max)
{
max = a[i];
}
if (a[i] < min)
{
min = a[i];
}
}
System.out.println("Largest Number in a given array is : " + max);
[Type the document title]
AKASH NAIR
6151

System.out.println("Smallest Number in a given array is : " + min);


}
}
Output-

PRACTICAL-4
1.Designed a class SortData that contains the method asec() and desc().
import java.util.*;
class test
{
Scanner input=new Scanner(System.in);
int num,i;
int arr[];
int temp=0;
public void getdata()
{
System.out.print("Enter the size of array: ");
num=input.nextInt();
arr=new int[num];
System.out.print("Enter the number: ");
[Type the document title]
AKASH NAIR
6151

for( i=0;i<num;i++)
{
arr[i]=input.nextInt();
}
}
void putdata()
{
System.out.print("Given numbers are: ");
for(i=0;i<num;i++)
{
System.out.println(arr[i]);
}
}
void asce()
{
for(i=0;i<num;i++)
{
for(int j=i+1;j<num;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.print("Ascending order of number are: ");
for(int i=0;i<num;i++)
{
System.out.println(arr[i]);
}
}
void desc()
{
for(i=0;i<num;i++)
{
for(int j=i+1;j<num;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
[Type the document title]
AKASH NAIR
6151

}
System.out.print("Descending order of number are: ");
for(int i=0;i<num;i++)
{
System.out.println(arr[i]);
}
}
public static void main(String args[])
{
test ob=new test();
ob.getdata();
ob.putdata();
ob.asce();
ob.desc();
}
}

2.Designed a class that demonstrates the use of constructor and destructor.


class xyz
{
xyz()
{
System.out.println("Constructor method........");
}
protected void finalize()
{
System.out.print("Garbage Collected.....");
[Type the document title]
AKASH NAIR
6151

}
}
class prac4B
{
public static void main(String args[])
{
xyz ob=new xyz();
ob=null;
System.gc();
}
}

3.Write a java program to demonstrate the implementation of abstract class.

abstract class Calc


{
public abstract int sqr(int n1);
public abstract int cube(int n1);
public void show()
{
System.out.println("Hello");
}
}
class Pract4 extends Calc
{
public int sqr(int n1)
{
return n1*n1;
}
public int cube(int n1)
{
return n1*n1*n1;
}
public static void main(String ar[])
{
Pract4 rt=new Pract4();
[Type the document title]
AKASH NAIR
6151

System.out.println(rt.sqr(4));
System.out.println(rt.cube(5));
rt.show();
}
}
[Type the document title]
AKASH NAIR
6151

PRACTICAL-5
1.Write a java program to implement single level inheritance.
class num
{
int a=2,b=4,c;
}
class sum extends num
{
void add()
{
c=a+b;
System.out.print("sum is "+c);
}
public static void main(String ar[])
{
sum s=new sum();
s.add();
}
}

2.Write a java program to implement method overriding


class base
{
void show()
System.out.print("BASE");
}
class child extends base
{
void show()
{
System.out.print("CHILD");
}
[Type the document title]
AKASH NAIR
6151

public static void main(String ar[])


{
child c=new child();
c.add();
}
}

3.Write a java program to implement multiple inheritance.

interface I1
{
public void show();
}
interface T extends I1
{
public void display();
}
class multi implements T
{
public void show()
{
System.out.println("From interface I1");
}
public void display()
{
System.out.println("From interface T");
}
public static void main(String ar[])
{
multi m1=new multi();
m1.show();
m1.display();
}
}
[Type the document title]
AKASH NAIR
6151

PRACTICAL-6
1.Create a package, Add the necessary classes and import the package in java class.

Add.java
package cal;
public class add
{
public void show1()
{
System.out.println("addition");
}
}

Sub.java
package cal;
public class sub
{
public void show2()
{
System.out.println("subtraction");
}
}
Pack.java
import cal.*;
class pack
{
public static void main(String args[])
{
sub s=new sub();
s.show2();
add a=new add();
a.show1();
}
}
Output:
[Type the document title]
AKASH NAIR
6151

2.Write a java program to add two matrices and print the resultant matrix.
import java.util.Scanner;
class AddTwoMatrix
{
public static void main(String args[])
{
int m, n, c, d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[][] = new int[m][n];
System.out.println("Enter the elements of first matrix");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
first[c][d] = in.nextInt();
System.out.println("Enter the elements of second matrix");
for (c = 0 ; c < m ; c++)
for (d = 0 ; d < n ; d++)
second[c][d] = in.nextInt();
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
sum[c][d] = first[c][d] + second[c][d];
System.out.println("Sum of the matrices:");
for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
System.out.print(sum[c][d]+"\t");
System.out.println();
}
}
}
[Type the document title]
AKASH NAIR
6151

3.Write a java program for multiplying two matrices and print the product for the
same.
import java.util.Scanner;
class MatrixMultiplication
{
public static void main(String args[])
{
int m, n, p, q, sum = 0, c, d, k;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of first matrix");
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
System.out.println("Enter elements of first matrix");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
first[c][d] = in.nextInt();
System.out.println("Enter the number of rows and columns of second matrix");
p = in.nextInt();
q = in.nextInt();
if (n != p)
System.out.println("The matrices can't be multiplied with each other.");
else
{
int second[][] = new int[p][q];
int multiply[][] = new int[m][q];
[Type the document title]
AKASH NAIR
6151

System.out.println("Enter elements of second matrix");


for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
second[c][d] = in.nextInt();
for (c = 0; c < m; c++)
{
for (d = 0; d < q; d++)
{
for (k = 0; k < p; k++)
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
System.out.println("Product of the matrices:");
for (c = 0; c < m; c++)
{
for (d = 0; d < q; d++)
System.out.print(multiply[c][d]+"\t");
System.out.print("\n");
}
}
}
}
[Type the document title]
AKASH NAIR
6151

PRACTICAL-7

1.Write a java program to implement the vectors


import java.util.*;
class test
{
public static void main(String ar[])
{
Vector<String>v=new Vector<String>();
v.add("Red");
v.add("Green");
v.add("Blue");
System.out.println(v);
v.add(2,"Yellow");
System.out.println(v);
System.out.println("element at 3rd position="+v.get(3));
System.out.println("1st element ="+v.firstElement());
System.out.println("last element ="+v.lastElement());
[Type the document title]
AKASH NAIR
6151

System.out.println("size ="+v.size());
System.out.println("vector empty? ="+v.isEmpty());
if(v.contains("Red"))
System.out.println("Red is present");
else
System.out.println("Red not present");
}
}

2. Write a java program to implement thread life cycle.


class demo1 extends Thread
{
int i;
public void run()
{
try
{
System.out.println("this is thread");
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
class cycle
{
public static void main(String args[])
{
[Type the document title]
AKASH NAIR
6151

demo1 d1=new demo1();


d1.start();
}
}

3. Write a java program to implement multithreading.

class demo1 extends Thread


{
int i;
public void run()
{
try
{
for(i=1;i<=10;i++)
{
System.out.println("i="+i);
Thread.sleep(100);
}
}
catch(Exception e)
{
}
}
}
class demo2 extends Thread
[Type the document title]
AKASH NAIR
6151

{
int i;
public void run()
{
try
{
for(i=10;i>=1;i--)
{
System.out.println("i="+i);
}
}
catch(Exception e)
{
}
}
}
class life
{
public static void main(String args[])
{
demo1 d1=new demo1();
demo2 d2=new demo2();
d1.start();
d2.start();
}
}
[Type the document title]
AKASH NAIR
6151

PRACTICAL – 8
1.Write a java program to open a file and display the contents in the console
window.

Import java.io.*;
Class Read
{
Public static void main(String args[])throws Exception
{
int c;
[Type the document title]
AKASH NAIR
6151

FileInputStream in=new FileInputStream("one.txt");


try
{
c=(int)in.read();
while(c!=-1)
{
System.out.print((char)c);
c=(int)in.read();
}
in.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

2. Write a java program to copy the contents from one file to other file.

Import java.io.*;
Class copy
{
public static void main(String args[])throws Exception
{
int c;
FileInputStream in=new FileInputStream("1.txt");
FileOutputStream op=new FileOutputStream("2.txt");
try
[Type the document title]
AKASH NAIR
6151

{
c=(int)in.read();
while(c!=-1)
{
System.out.print((char)c);
c=(int)in.read();
op.write(c);
}
in.close();
op.close();
}
catch(Exception e)
{
}
}
}

2.txt
[Type the document title]
AKASH NAIR
6151

3.Write a java program to read the student data from user and store it in the file.

import java.io.*;

class write
{
public static void main(String args[])throws Exception
{
String name;
FileOutputStream op=new FileOutputStream("2.txt");
DataInputStream s=new DataInputStream(System.in);
try
{
System.out.print("Enter the Student Data:");
name=s.readLine();
op.write(name.getBytes(),0,name.length());
}
catch(Exception e)
{
}
op.close();
}
}

2.txt:-
[Type the document title]
AKASH NAIR
6151

PRACTICAL:- 9
1.Design a AWT program to print the factorial for an input value.

import java.awt.*;
import java.awt.event.*;

class factn extends Frame implements ActionListener


{
TextField t1=new TextField();
TextField t2=new TextField();
Label L1=new Label("Enter a Number:");
Label L2=new Label("Factorial :");
Button b1 = new Button("FACT!");
factn()
{

L1.setBounds(30,50,100,50);
t1.setBounds(240,50,50,20);

L2.setBounds(30,100,100,50);
t2.setBounds(240,80,50,20);

b1.setBounds(30,200,100,50);
add(L1);
add(t1);
add(L2);
[Type the document title]
AKASH NAIR
6151

add(t2);
add(b1);
b1.addActionListener(this);
setSize(200,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if(str.equals("FACT!"))
{
int i;
int n=Integer.parseInt(t1.getText());
int fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;

}
String d=Integer.toString(fact);
t2.setText(String.valueOf(d));
}
}
public static void main(String args[])
{
factn f1= new factn();
}
}
[Type the document title]
AKASH NAIR
6151

2. Design an AWT program to perform various string operations like


reverse string,string concatenation etc.

import java.awt.*;
import java.awt.event.*;

class string extends Frame implements ActionListener


{
TextField t1=new TextField();
TextField t2=new TextField();
TextField t3=new TextField();
string()
{
Label l1=new Label("Enter String 1");
l1.setBounds(30,30,100,30);
t1.setBounds(130,30,120,30);

Label l2=new Label("Enter String 2");


l2.setBounds(30,70,100,30);
t2.setBounds(130,70,120,30);

Label l3=new Label("Result");


l3.setBounds(30,110,100,30);
t3.setBounds(130,110,120,30);
[Type the document title]
AKASH NAIR
6151

Button b1=new Button("Reverse1");


b1.setBounds(30,150,50,30);
Button b2=new Button("Reverse2");
b2.setBounds(100,150,50,30);
Button b3=new Button("Concate");
b3.setBounds(170,150,50,30);
add(l1);
add(l2);
add(t1);
add(t2);
add(b1);
add(b2);
add(b3);
add(l3);
add(t3);
setLayout(null);
setSize(300,300);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if(str.equals("Reverse1"))
{
String a=t1.getText();
String ab="";
for(int i=a.length()-1;i>=0;i--)
{
ab=ab+(a.charAt(i));
}
t3.setText(ab);
}
if(str.equals("Reverse2"))
{
String a=t2.getText();
String ab="";
for(int i=a.length()-1;i>=0;i--)
{
ab=ab+(a.charAt(i));
}
t3.setText(ab);
}
[Type the document title]
AKASH NAIR
6151

if(str.equals("Concate"))
{
String a1=t1.getText();
String a2=t2.getText();
t3.setText(a1+a2);
}
}
public static void main(String args[])
{
string f=new string();
}
}
[Type the document title]
AKASH NAIR
6151

3.Write a java program to implement exception handling.

import java.io.*;

class MyException extends Exception


{
MyException(String msg)
{
super(msg);
}
}

class login
{
DataInputStream s=new DataInputStream(System.in);
public static void main(String args[])throws Exception
{
String pwd="1234",p;
DataInputStream s=new DataInputStream(System.in);
[Type the document title]
AKASH NAIR
6151

try
{
System.out.println("Enter your password:");
p=s.readLine();
if(p.equals(pwd))
{
throw new MyException("Authentication Successfull!!");
}
else
{
throw new MyException("Authentication Failure!!");
}
}
catch(MyException e)
{
System.out.println(e);
}
}
}
[Type the document title]
AKASH NAIR
6151

PRACTICAL:-10

1.Design a calculator based on AWT application.


import java.io.*;
import java.awt.*;
import java.awt.event.*;
class demor extends Frame implements ActionListener
{
GridLayout G = new GridLayout(3,5);
Label l1 = new Label("First Number");
TextField t1 = new TextField();
Label l2 = new Label("Second Number");
TextField t2 = new TextField();
Label l3 = new Label("Answer");
TextField t3 = new TextField();
int flag;
String s1,s2;
demor()
{
l1.setBounds(50,100,100,20);
t1.setBounds(200,100,100,20);
l2.setBounds(50,140,100,20);
t2.setBounds(200,140,100,20);
l3.setBounds(50,180,100,20);
t3.setBounds(200,180,100,20);
int k = 0;
Button b1 = new Button("+");
b1.addActionListener(this);
Button b2 = new Button("-");
b2.addActionListener(this);
Button b3 = new Button("*");
b3.addActionListener(this);
Button b4 = new Button("/");
b4.addActionListener(this);
Button b5 = new Button("Enter");
b5.addActionListener(this);
Button b6 = new Button("0");
[Type the document title]
AKASH NAIR
6151

b6.addActionListener(this);
Button b7 = new Button("1");
b7.addActionListener(this);
Button b8 = new Button("2");
b8.addActionListener(this);
Button b9 = new Button("3");
b9.addActionListener(this);
Button b10 = new Button("4");
b10.addActionListener(this);
Button b11 = new Button("5");
b11.addActionListener(this);
Button b12 = new Button("6");
b12.addActionListener(this);
Button b13 = new Button("7");
b13.addActionListener(this);
Button b14 = new Button("8");
b14.addActionListener(this);
Button b15 = new Button("9");
b15.addActionListener(this);
b1.setBounds(50,250,50,20);
b2.setBounds(110,250,50,20);
b3.setBounds(170,250,50,20);
b4.setBounds(230,250,50,20);
b5.setBounds(290,250,50,20);
b6.setBounds(50,280,50,20);
b7.setBounds(110,280,50,20);
b8.setBounds(170,280,50,20);
b9.setBounds(230,280,50,20);
b10.setBounds(290,280,50,20);
b11.setBounds(50,310,50,20);
b12.setBounds(110,310,50,20);
b13.setBounds(170,310,50,20);
b14.setBounds(230,310,50,20);
b15.setBounds(290,310,50,20);
add(l1);
add(l2);
add(l3);
add(t1);
add(t2);
add(t3);
[Type the document title]
AKASH NAIR
6151

add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b10);
add(b11);
add(b12);
add(b13);
add(b14);
add(b15);
setSize(800,900);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int n1 = Integer.parseInt(t1.getText());
int n2 = Integer.parseInt(t2.getText());
String Str = e.getActionCommand();
if(Str.equals("+"))
{
int c = Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText());
t3.setText(Integer.toString(c));
}
if(Str.equals("-"))
{
int c = Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText());
t3.setText(Integer.toString(c));
}
if(Str.equals("*"))
{
int c = Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText());
t3.setText(Integer.toString(c));
}
if(Str.equals("/"))
[Type the document title]
AKASH NAIR
6151

{
int c = Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText());
t3.setText(Integer.toString(c));
}
if(Str.equals("Enter"))
{
flag=1;
}
if(Str.equals("0"))
{
if(flag==0)
{
s1=s1+"0";
t1.setText(s1);
}
if(flag==1)
{
s2=s2+"0";
t2.setText(s2);
}
}
if(Str.equals("1"))
{
if(flag==0)
{
s1=s1+"1";
t1.setText(s1);
}
if(flag==1)
{
s2=s2+"1";
t2.setText(s2);
}
}
if(Str.equals("2"))
{
if(flag==0)
{
s1=s1+"2";
t1.setText(s1);
[Type the document title]
AKASH NAIR
6151

}
if(flag==1)
{
s2=s2+"2";
t2.setText(s2);
}
}
if(Str.equals("3"))
{
if(flag==0)
{
s1=s1+"3";
t1.setText(s1);
}
if(flag==1)
{
s2=s2+"3";
t2.setText(s2);
}
}
if(Str.equals("4"))
{
if(flag==0)
{
s1=s1+"4";
t1.setText(s1);
}
if(flag==1)
{
s2=s2+"4";
t2.setText(s2);
}
}
if(Str.equals("5"))
{
if(flag==0)
{
s1=s1+"5";
t1.setText(s1);
}
[Type the document title]
AKASH NAIR
6151

if(flag==1)
{
s2=s2+"5";
t2.setText(s2);
}
}
if(Str.equals("6"))
{
if(flag==0)
{
s1=s1+"6";
t1.setText(s1);
}
if(flag==1)
{
s2=s2+"6";
t2.setText(s2);
}
}
if(Str.equals("7"))
{
if(flag==0)
{
s1=s1+"7";
t1.setText(s1);
}
if(flag==1)
{
s2=s2+"7";
t2.setText(s2);
}
}
if(Str.equals("8"))
{
if(flag==0)
{
s1=s1+"8";
t1.setText(s1);
}
if(flag==1)
[Type the document title]
AKASH NAIR
6151

{
s2=s2+"8";
t2.setText(s2);
}
}
if(Str.equals("9"))
{
if(flag==0)
{
s1=s1+"9";

t1.setText(s1);
}
if(flag==1)
{
s2=s2+"9";
t2.setText(s2);
}
}
}
public static void main(String args[])throws Exception
{
demor obj = new demor();
obj.t1.setText("0");
obj.t2.setText("0");
obj.flag=0;
obj.s1="0";
obj.s2="0";
}
}
[Type the document title]
AKASH NAIR
6151

Das könnte Ihnen auch gefallen