Unable to increment a variable scanned in java [duplicate]

Home / java / Unable to increment a variable scanned in java [duplicate]

This question already has an answer here:concatenating string and numbers Java 6 answers

Hello I’m a beginner in Java and i’m finding issuses to increment the variable age as it is red as a string or it is an integer This is the Code :public static void main(String[] args)
Scanner name= new Scanner(System.in);
System.out.println("Hello your name is "+name.nextLine());
Scanner in = new Scanner(System.in);
int age = in.nextInt();
System.out.println("In 17 September i will become "+age+1+" years old");


Whenever you add a String in a print statement, all further + signs are considered to be the concatenation operator, instead of the addition sign.

To fix, enclose it in brackets, like (age+1).
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *