Programmers sometimes print the numbers 1 through n on two lines at the top of a
ID: 3635893 • Letter: P
Question
Programmers sometimes print the numbers 1 through n on two lines at the top of a page, to show the respective columns in the output.For example, for n=45 the two lines would be
000000000111111111122222222223333333333444444
123456789012345678901234567890123456789012345
Each two-digit number is read vertically: 2 is above column 27, etc.
7
Write a static method that will accept the value of the int parameter n and print the two lines of numbers for that value of n. Do not do any defensive programming: the value of n is guaranteed to be between 1 and 80. Make 10 a named constant.
Explanation / Answer
please rate - thanks
import java.util.*;
public class main
{static int ten=10;
public static void main(String [] args)
{Scanner in=new Scanner(System.in);
int n;
System.out.print("Enter a number between 1 and 80: ");
n=in.nextInt();
printLines(n);
}
public static void printLines(int n)
{int i;
for(i=1;i<=n;i++)
System.out.print(i/ten);
System.out.println();
for(i=1;i<=n;i++)
System.out.print(i%10);
System.out.println();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.