Good day. Carried out the task on http://informatics.msk.ru/ under number 112202. Task:
Write a program that introduces two integers and finds their product without using the multiplication operation. Note that the numbers may be negative.
When checking, 19 out of 24 tests were performed, or 15 and 24. Alas, test conditions are not available to me. Please tell me, how else can you improve the code? Can use BufferedReader ()?
In my code:
import java.util.Scanner; class Series{ static Scanner in = new Scanner(System.in); public static void main (String[] args){ int x = in.nextInt(), a = in.nextInt(), i=0; long c=0; if(a>=0){ while(i!=a){ c+=x; i++;} }else{ while(i!=x&i!=-x){ //при замене "x" на "a" , c+=a; //"a" на "x" тесты показывают 15 из 24 i++;} } System.out.println(c); } }