Hi everyone,
can you please share source code on how to get 9's complment of a given number (up to 4 digit number, ex 9's Compment when you enter a single digit up to 4 digit number. i tried the program below but it has errors.
public class Main
{
public static void main(String[] args) {
String new1 = Integer.toString(result1);
String new2 = Integer.toString(result2);
String new3 = Integer.toString(result3);
String new4 = Integer.toString(result4);
String newNN = New1 + New2 + New3 + New4;
Int newN = Integer.parseInt(newNN);
int firstAnswer = newNN + m ;
String firstAnswer2 = Integer.toString(firstAnswer);
String finalAnswer = Character.toString(firstAnswer2.charAt(0));
String finalAns1 = Character.toString(firstAnswer2.charAt (1));
String finalAns2 = Character.toString(firstAnswer2.charAt (2));
String finalAns3 = Character.toString(firstAnswer2.charAt (3));
String finalAns4 = Character.toString(firstAnswer2.charAt (4));
String newNN = finalAns1 + finalAns2 + finalAns3 + finalAns4;
Int newN2 = Integer.parseInt(newNN2);
Int newN3 = Integer.parseInt(finalAnswer);
Ins Answer = newN2 + newN3;
System.out.println("Answer: " + answer + "\n"
+ "9's Complement of " + n + " is " + newNN);
}
}