Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fill in the skeleton below for a program that prompts the user for an integer. T

ID: 3804327 • Letter: F

Question

Fill in the skeleton below for a program that prompts the user for an integer. The program should then display a triangle of the numbers as shown below. The program should continue prompting for input until the user enters a negative number. The program should end with a Goodbye! message. See below for an example of the program in action. Make sure your code produces the same output as that given in the transcript below. Please note that a correct solution to this problem will NOT make use of any arrays.

Here is a sample transcript of how the program should work.

Input typed by the user is indicated by bold text:

Enter an integer: 3 33 333

Enter an integer: 2 22

Enter an integer: -1 Goodbye!

import java.util.Scanner;

public class Exam2B { public static void main(String[] args)

{ Scanner in = new Scanner(System.in); // your code goes here

Explanation / Answer

import java.util.Scanner;
public class Exam2B
{
public static void main(String args[])
{
int t,n,i,d=0;
Scanner sc =new Scanner(System.in);
do
{
  
System.out.println("Enter an integer :");
n=sc.nextInt();
d=n;
if(n<0)
{
System.out.println("Goodbye!");
break;
}
for(i=1;i<n;i++)
{
t=(d*10)+n;
System.out.println(t);
d=t;
}
}while(n>=0);
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote