0

What did I do wrong here??

import.java.util.Scanner; public class Program { public static void main(String[] args) { Scanner name = new Scanner(system.in); Scanner age = new Scanner(system.in); System.out.println("Enter your full names"); String names = name.nextLine(); System.out.println("Enter your full names"); String ages = age.nextAge(); System.out.printf("%s is %s years old",names,ages); } }

18th Dec 2022, 6:29 AM
Katlego Prince
Katlego Prince - avatar
2 Answers
+ 1
1) You don't need to declare 2 Scanners 2) int is used for like normal numbers not Strings import.java.util.Scanner; // this is supposed to be "import java.util.Scanner; " public class Program { public static void main(String[] args) { Scanner name = new Scanner(system.in); // Capital S in (System.in) Scanner age = new Scanner(system.in); // Capital S in (System.in) System.out.println("Enter your full names"); String names = name.nextLine(); System.out.println("Enter your full names"); // ("its Enter your age?") String ages = age.nextAge(); // its supposed to be int not String //just age.nextInt since its int System.out.printf("%s is %s years old",names,ages); // its- System.out.println( names +" is " + ages + " years old"); } }
18th Dec 2022, 6:53 AM
Sharafath Mohamed
Sharafath Mohamed - avatar
0
Okay thank you
18th Dec 2022, 7:38 AM
Katlego Prince
Katlego Prince - avatar