In: Computer Science
Computer Organization
Input your age (my age is 20 years old) and display what your age would be next year(21 year)
Submit screen shots from Marie.
I think this should display on Java programming Language
Below is code in JAVA for the given problem statement.
I have mentioned inline comments for better understanding of code.
Do let me know in comments in case of any doubt.
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
//scanner object will be used to read input given by user
Scanner sc = new Scanner(System.in);
System.out.print("Enter your age:");
int age = sc.nextInt(); // read the age entered by user
// age after 21 years would be age+21 so update the value of age and display the result
age = age+21;
System.out.println("Your age after 21 years would be : "+age);
}
}
Screenshot of code:
Sample Output:
1):
2):