+ 1
What process or method in java i use to define my inputted integer that it is negative or positive?
example .if i input 2 negative integers it will terminate at ask to input again another integers .. and if i input 2 positive integer it will multifly both numbers
10 odpowiedzi
+ 12
import java.util.Scanner;
public class main {
public static void main (String[] args) {
Scanner reader = new Scanner(System.in);
While (true) {
System.out.println("Enter number 1:");
int n1 = reader.nextInt();
System.out.println("Enter number 2:");
int n2 = reader.nextInt();
if (n1 >= 0 && n2 >= 0) {
int p = n1 * n2;
System.out.println(p);
break;
}
}
}
}
This should do the job. Hope it helps. =)
+ 12
Use the code I've mentioned above, the while loop will keep looping and asking for both positive input. The loop will only break if both inputs are positive.
+ 12
then the it will loop and ask you for number again
+ 12
No problem, glad to help. 😁
+ 2
hi if you provide 2 negative integers that becomes positive right.
+ 1
i want the program if i nput negative integers the program will ask again to input another integer ... thats my problem now .. what are the process or method i use?
+ 1
tnx shadow i try it to run in my compiler ..
+ 1
if i input negative integer?
+ 1
much*
0
wow thnk you so match shdow .. i will study your code