+ 1

What is wrong with my code?

import java.util.Scanner;//*import scanner class public class Program { public static void main(String[] args) { Scanner myObj= new Scanner(System.in); int integer1, integer2, integer3,sum=0, average=0;//*Declaration of Variable System.out.println("Input #1: "); integer1 = myObj.nextInt(); System.out.println(integer1); System.out.println("Input #2: "); integer2 = myObj.nextInt(); System.out.println(integer2); System.out.println("Input #3: "); integer3 = myObj.nextInt(); System.out.println(integer3); sum=integer1+integer2+integer3; average= (integer1+integer2+integer3)/3; System.out.println(integer1+"+"+integer2+"+"+integer3+"="+sum); System.out.println("The average is "+average); System.out.println("The first input is "+integer1);

18th Aug 2024, 2:51 AM
Ghynne
Ghynne - avatar
1 Answer
+ 4
you did not close main and class. where are the 2 closing brackets? } } One way to prevent mistakes like these is to close them first before writing the contents. Same with parenthesis, specially nested ones where it is easy to lose track of the opening and closing pairs.
18th Aug 2024, 4:14 AM
Bob_Li
Bob_Li - avatar