0% found this document useful (0 votes)
28 views1 page

Tp2 Se

The document is a Java program that defines a class 'Tpse' containing a nested class 'MyThread' which extends Thread. It prompts the user for two integers, calculates their sum using the 'sum' method, and attempts to print the result using a thread. However, there are several syntax errors and issues in the code that need to be addressed for it to function correctly.

Uploaded by

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

Tp2 Se

The document is a Java program that defines a class 'Tpse' containing a nested class 'MyThread' which extends Thread. It prompts the user for two integers, calculates their sum using the 'sum' method, and attempts to print the result using a thread. However, there are several syntax errors and issues in the code that need to be addressed for it to function correctly.

Uploaded by

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

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tpse;

import java.util.Scanner;
public class Tpse {
public static class MyThread extends Thread {

@Override
public synchronized void start() {
super.start(); //To change body of generated methods, choose Tools |
Templates.
}

int a ;
int b ;
public MyThread(int a , int b){
this.a = a ;
this.b = b ;
}
public static int sum(int a , int b){
int s = 0 ;
for (int i=a ; i<=b ; i++){
s += i ;}
return s ;
}
public void run(){
System.out.println("the sum from"+a+"to"+b+"is"+res+); }
}}
public string getresult(){
return res ;}

public static void main(String[] args)throws InterruptedException {

Scanner scanner = new Scanner(System.in);


System.err.println("give your first number a");
int a = Scanner.nextInt();

System.err.println("give your second number b");


int b = Scanner.nextInt();

int res = sum(a,b);


MyThread T1 = new MyThread;
T1.start();
MyThread.sleep(2000);
System.out.println(T1.getresult());

You might also like