CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Alex Balandinos
Level 18
Lusaka
  • 29.01.2019
  • 1495views
  • 3comments

Hey there tried another way still get the same error..can anyone help me find the solution

Question about the task Plan to conquer the world
Java Syntax,  Level 3,  Lesson 8
Resolved


Enter the number and name from the keyboard. Display the following string:
<name> will take over the world in <number> years. Mwa-ha-ha!

Here's an example:
Kevin will take over the world in 8 years. Mwa-ha-ha!

The order in which the data is input matters a lot.

Requirements:
  • The program should output text.
  • The program must read data from the keyboard.
  • The displayed text must contain the entered name.
  • The displayed text must contain the entered number.
  • The displayed text must fully match the task conditions.
package com.codegym.task.task03.task0318; /* Plan to conquer the world */ import java.io.*; import java.util.Scanner; public class Solution { public static void main(String[] args) throws Exception { //write your code here // int number; Scanner name = new Scanner(System.in); Scanner number = new Scanner( System.in); System.out.print( name.nextLine() +" will take over the world in " + number.nextInt() + " years. Mwa-ha-ha!"); // System.out.print(name.nextLine() + " years. Mwa-ha-ha!"); // int number= a.nextInt(); // System.out.println( name + " will take over the world in " + number + " years. Mwa-ha-ha!"); } }
0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
29 January 2019, 21:36solution
#1 The requirements state that you must: Enter the number and name. The code above has name then number. #2 read this article about a Scanner class issue that you will face with your code: https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo I know you are learning, but you don't need to declare but one Scanner:
Scanner reader = new Scanner(System.in);

reader.readLine();
reader.nextInt();
This works just fine. Line 16 is your major issue though because you are reading name first then number (as i pointed out above). You will need to figure out how to read number first, then name, then output the required text.
+2
Alex Balandinos
Level 18 , Lusaka, Zambia
30 January 2019, 08:22
Thanks mate..line 16 has major issue's will work around it. in stacks all they saying is putting nextInt on top of nextLine u know will try URS ..I 'lllet u know how it goes
+1
Alex Balandinos
Level 18 , Lusaka, Zambia
30 January 2019, 09:49
It is done thanks
+1
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.