0% found this document useful (0 votes)
24 views5 pages

00111604421

The document contains solutions to two programming questions. The first question involves creating a class that prints palindrome numbers between 10-100 using threads. The second question involves creating a GUI with a text area to accept user feedback, and displaying the word and character count when a submit button is clicked.

Uploaded by

Nibba Toni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

00111604421

The document contains solutions to two programming questions. The first question involves creating a class that prints palindrome numbers between 10-100 using threads. The second question involves creating a GUI with a text area to accept user feedback, and displaying the word and character count when a submit button is clicked.

Uploaded by

Nibba Toni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Set - 1

Enrollment id - 00111604421

Q1.

A PalindromesViaThreads class that prints the prints 10 palindrome numbers(11,22,33) between 10 and
100 using Threads implemented via Extending Thread Class.

Solutioin

package palindromesviathread;

class MyThread extends Thread

public synchronized void run()

int n, b, rev=0;

System.out.println("Palindrome numbers between 10 and 100 are : ");

for(int i=10; i<=100; i++)

n=i;

while(n>0)

b = n % 10;

rev = rev*10+b;

n = n/10;

if(rev == i)

System.out.println(i+" ");
}

rev = 0;

public class PalindromesViaThread

public static void main(String[] args)

try {

MyThread t = new MyThread();

Thread t1 = new Thread(t);

t1.start();

t1.join();

catch (Exception ex) {

System.out.println("Exception "+ex);

}
Q2.

Prompt user to enter some feedback for Java course taught in a JTextArea. When the user clicks on
submit, count and display the number of words and characters input in the JTextArea?

Solution

package feedbackforjava;

import java.awt.event.*;

import javax.swing.*;

class MyFrame extends JFrame implements ActionListener

JLabel lwords,lchar;

JTextArea area;

JButton b;

MyFrame()

super("Feedback For Java ");

lwords=new JLabel();

lwords.setBounds(50,25,100,30);

lchar=new JLabel();

lchar.setBounds(160,25,100,30);

area=new JTextArea();

area.setBounds(20,75,350,150);

b=new JButton("Count Words");

b.setBounds(100,300,120,30);
b.addActionListener(this);

add(lwords);

add(lchar);

add(area);

add(b);

setLayout(null);

public void actionPerformed(ActionEvent e){

String text=area.getText();

String words[]=text.split("\\s");

lwords.setText("Words: "+words.length);

lchar.setText("Characters: "+text.length());

public class FeedbackForJava

public static void main(String[] args)

MyFrame f = new MyFrame();

f.setSize(500, 500);

f.setVisible(true);

You might also like