0

Can any one solve this code for me? I want it to give desired output on single required input, will any one help me?

import java.util.Scanner; class Myage { public static void main(String[] args) { int a=12; int b=13; int c=7; { { String d, e; d="Months"; e="Years"; { System.out.println("I am " + (a+b)+" "+e+" & "+c+" "+d+" old. What about you"); { Scanner yes = new Scanner(System.in); //declaring new scanner with name myVar System.out.println("Can I know your Age:"); System.out.println("She: "+yes.nextInt()); { if(yes.nextInt()>18 && yes.nextInt()<=26) { System.out.println(" Right age to get married") ; }else if(yes.nextInt() <18) { System.out.println(" you are still a kid") ; } else if(yes.nextInt() >26) { System.out.println("Sorry you should have contacted us earlier") ; } } } } } } } } } https://code

4th Oct 2018, 1:25 PM
Shrikant
Shrikant - avatar
2 odpowiedzi
+ 2
yes.nextInt () - you must enter the number each time you use nextInt. you must create an int variable and assign a given number to it by the user and then use this variable. System.out.println ("Can I know your age:"); int age = yes.nextInt (); System.out.println ("She:" + age); { if (age> 18 && age <= 26) { System.out.println ("Right age to get married"); } else if (age <18) { System.out.println ("you are still a kid"); } else if (age> 26) { System.out.println ("Sorry you should have contacted us earlier"); } }
4th Oct 2018, 5:29 PM
Daniel (kabura)
Daniel (kabura) - avatar
0
Thank you so much Daniel.....
4th Oct 2018, 5:36 PM
Shrikant
Shrikant - avatar