Question

Need help correcting code from error output if you compare the two it says that from my output i have a extra enter key but the expected output shows no enter key

import java.util.*;
import java.io.*;
import java.util.Scanner;
public class CountByAnything{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
System.out.println("Counting by "+n+" up to "+n*100 +":");
int i=1;
while(i<=100){
System.out.print(n*i+" ");
if(i%10==0)
System.out.println();
i++;
}
}
}

1. Compare output Input Counting by 9 up to 900 9 18 27 36 45 54 63 72 81 90 99 108 117 126 135 144 153 162 171 180 189 198 207 216 225 234 243 252 261 270 279 288 297 306 315 324 333 342 351 360 369 378 387 396 405 414 423 432 441 450 Your output 459 468 477 486 495 504 513 522 531 540 549 558 567 576 585 594 603 612 621 630 639 648 657 666 675 684 693 702 711 720 729 738 747 756 765 774 783 792 801 810 819 828 837 846 855 864 873 882 891 900 Counting by 9 up to 900 9 18 27 36 45 54 63 72 81 90 99 108 117 126 135 144 153 162 171 180 189 198 207 216 225 234 243 252 261 270 279 288 297 306 315 324 333 342 351 360 369 378 387 39 405 414 423 432 441 450 Expected output 4.59 468 4 77 486 495 504 513 522 531 5 40 549 558 567 576 585 594 603 612 621 630 639 648 657 666 675 684 693 702 711 720 729 738 747 756 765 774 783 792 801 810 819 828 837 846 855 864 873 882 891 900 0/2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//your code is absolutely fine, it is showing output as expected..

//i have attached an screenshot of output

//may be due to your compiler you not getting output..

import java.util.*;
import java.io.*;
import java.util.Scanner;
public class CountByAnything{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
System.out.println("Counting by "+n+" up to "+n*100 +":");
int i=1;
while(i<=100){
System.out.print(n*i+" ");
if(i%10==0)
System.out.println();
i++;
}
}
}

Add a comment
Know the answer?
Add Answer to:
Need help correcting code from error output if you compare the two it says that from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Programming: Using a single for loop, output the even numbers between 2 and 1004...

    In C++ Programming: Using a single for loop, output the even numbers between 2 and 1004 (inclusive) that iterates (loops) exactly 502 times. The outputted numbers be aligned in a table with 10 numbers per row. Each column in the table should be 5 characters wide. Do not nest a loop inside of another loop. Hint: First create and test the code that output the numbers all on one line (the command line will automatically wrap the output to new...

  • need help to complete this java program // add appropriate import statements here. // These imports...

    need help to complete this java program // add appropriate import statements here. // These imports you can leave as is. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; import javafx.stage.Stage; /** @author yourAccountNameHere */ public class ConnectTheDots extends Application {            /*     * Do not add code to main(). Add it below in connectTheDots instead.     */     public static void main(String[] args) {         launch(args);     }         /*...

  • Create a program that will use the attached input file and perform the following operations. Read...

    Create a program that will use the attached input file and perform the following operations. Read the file into an appropriate JCF data structure. Look up a (list of) names and numbers matching a last name or the first letters of a last name, ignoring case. Look up a (list of) names and numbers matching a number or the first digits of a number. Add a name and number to the list. Sort the list by first name, last name...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT