Δημοσιεύτηκε: 09 Ιαν 2012, 23:23
από Star_Light
Η συνέχεια και του δικού μου κώδικα προηγουμένως βάζοντας μέσα το exception

Κώδικας: Επιλογή όλων


import java.util.Scanner;
import java.io.* ;

public class function {

static int dunami(int x)
{
int result=x*x;
return result;
}


public static void main(String args[])
{
int x;
int c;
Scanner input = new Scanner(System.in);

try{
System.out.print ("Give me an int : ") ;
x=input.nextInt();

c=dunami(x);

System.out.printf("The result is : %d " ,c);
} catch (Exception e)
{
System.out.println(" Κάτι δεν πάει καλα με αυτον τον κώδικα ");
}

}

}


EDIT: Για να καταλάβει κάποιος Πότε δεν πάει καλα κατι με το πρόγραμμα.... μπορεί να δώσει σαν είσοδο ένα string οταν του ζητηθεί ενας ακέραιος.

ΠΧ =>


Give me an int : ΗΕΛΛΟ
Κάτι δεν πάει καλα με αυτον τον κώδικα