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
hemant
Level 8
prayagraj
  • 31.05.2019
  • 991views
  • 2comments

i made a triangle of base 10 and height 10 but getting error! I have also proved it by run(without verification!

Question about the task Triangle of eights
Java Syntax,  Level 4,  Lesson 13
Under discussion

Using a for loop, display a right triangle of eights, with a base of 10 and a height of 10.

Example of screen output:
8
88
888
8888
88888
888888
8888888
88888888
888888888
8888888888

Requirements:
  • The program should not read numbers from the keyboard.
  • The program should display numbers on the screen.
  • The program should display a right triangle of eights, with a base of 10 and a height of 10.
  • The program must use a for loop.
package com.codegym.task.task04.task0437; /* Triangle of eights */ public class Solution { public static int n = 1; public static void main(String[] args) throws Exception { //write your code here for(int i = 0;i<10;i++){ rect(); n++; } } public static void rect(){ for(int i = 1;i<=n;i++){ if(n>10){ break; } System.out.print("8"); Solution.n=n; } System.out.print("\n"); } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Faizu Flc
Level 10 , Bangalore, India
5 May 2020, 04:28
* Triangle of eights Simple code */ public class Solution { public static void main(String[] args) throws Exception { for(int i = 1;i <= 10;i++) { for(int j = 1;j <= i;j++) { System.out.print("8"); } System.out.println(); } } }
+2
Show How
Level 8 , Newbury, United Kingdom
31 May 2019, 15:33
Your code looks ok to me but just give it a try by changing the string "8" to int 8 and see if it passes.
+2
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.