Δημοσιεύτηκε: 10 Ιαν 2012, 00:55
από Star_Light
Προσθέτω και μια for στο παραπάνω δημιουργώντας ενα νεο αντικείμενο εισόδου input2

αλλα μου χτυπαει στο for

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


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,y;
int c;

Scanner input1 = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);

System.out.println("Poses fores thes na ektelestei to programma?");
y=input2.nextInt();


for(int i=0; i<input2; i++)
{
try{
System.out.print ("Give me an int : ") ;
x=input1.nextInt();

c=dunami(x);

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

}

}
}


Κώδικας: Επιλογή όλων
for(int i=0; i<input2; i++)


στο i<input2 λεει -> The operator < is undefined for the argument type(s) int, Scanner

EDIT: LOL. Τι στόκμαν !

Κώδικας: Επιλογή όλων
for( int i=0; i<y; i++)


δουλευει ο κωδικας... εφοσον αναθέτω την τιμή στην μεταβλητή y.