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
Divakar Reddy
Level 15
Nandyal
  • 28.06.2019
  • 907views
  • 4comments

whats problem with my code

Question about the task Drawing a rectangle
Java Syntax,  Level 4,  Lesson 13
Under discussion


Use the keyboard to enter two numbers m and n.
Using a for loop, display an n x m rectangle made of eights.

Here's an example: m=2, n=4
8888
8888

Requirements:
  • The program should read two numbers from the keyboard.
  • The program should display text on the screen.
  • The program should display a n x m rectangle made of eights.
  • The program must use a for loop.
package com.codegym.task.task04.task0436; /* Drawing a rectangle */ import java.io.*; public class Solution { public static void main(String[] args) throws Exception { BufferedReader obj = new BufferedReader(new InputStreamReader (System.in)); String number1 = obj.readLine(); String number2 = obj.readLine(); int m=Integer.parseInt(number1); int n=Integer.parseInt(number2); int s=m*n; for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { System.out.print(s); } System.out.println(); } } }
0
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Divakar Reddy
Level 15 , Nandyal, India
28 June 2019, 08:53
there s=m*n; which equals to 8 . so i'm getting 8888 8888 as output
0
DeCC
Level 15 , Bielefeld, Germany
28 June 2019, 06:36
The problem is the 's' in your inner-Loop. You set s equal to m*n, which does not make any sense. Example: m = 5, n = 5 your output is: 2525252525 2525252525 2525252525 2525252525 2525252525 where it should be: 88888 88888 88888 88888 88888 You don't have to multiply something to solve this task ;)
0
Itachi
Level 16 , Brooklyn, US
28 June 2019, 06:32
that is the solution
0
Itachi
Level 16 , Brooklyn, US
28 June 2019, 06:32
double m=Double.parseDouble(reader.readLine()); double n=Double.parseDouble(reader.readLine()); for (int a=0;a<m;a++) { for (int b=0;b<n;b++) System.out.print("8"); System.out.println();} }
0
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.