Hi guys. I am having issues with the output of this program. Can somebody tell me what I have to do to make this work correctly? Here is the code I have so far:
import java.util.Scanner; //text scanner to parse primitive types and strings using regular expressions.
public class Operations {
private static Object total;
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner input=new Scanner (System.in);
int num1=0, num2=0;
System.out.printf("Enter First Number:\t ");
num1=input.nextInt();
System.out.printf("Enter Second Number:\t ");
num2=input.nextInt();
System.out.println("");
System.out.format("%1s%25s","Operation","Result\n");
String fmt = "%-28s %-7d \n";
String solution1= Integer.toString(num1) + "+" + Integer.toString(num2);
System.out.printf(fmt, solution1, total);
String format1 = "%-28s %-7d \n";
String solution2= Integer.toString(num1) + "-" + Integer.toString(num2);
System.out.printf(format1, solution2, total);
String format2 = "%-28s %-7d \n";
String solution3= Integer.toString(num1) + "*" + Integer.toString(num2);
System.out.printf(fmt, solution3, total);
String format3 = "%-28s %-7d \n";
String solution4= Integer.toString(num1) + "/" + Integer.toString(num2);
System.out.printf(fmt, solution4, total);
}
}
it gives off a couple of warnings but no errors and when I run the programI get this output:
Operation Result
5+6 null
5-6 null
5*6 null
5/6 null
which is exactly how I want it but it needs to give the answers not a null value.
I will be so grateful for your help. Thank you in advance.