import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // Validating the input if(n >= 20 && n <= 98) { // Running the countdown while(true) { System.out.print(n + " "); // Displaying the current value of the countdown // If the digits are the same, if(areDigitsIdentical(n)) { break; // Breaking out from the loop } // Decreasing the value of the countdown n--; System.out.println(""); } } else { System.out.println("Input must be 20-98"); // Displaying the appropriate message for InValid Input } } public static boolean areDigitsIdentical(int n) { int d0 = n % 10; // Extracting out the 1st digit int d1 = n / 10; // Extracting out the 2nd digit // If the two digits are the same, if(d0 == d1) return true; // Return true else // Otherwise, return false; // Return false } }   The language is Java. The output has to print a space after each number including the last one (The pictures shown is what the code needs to print as well as what the code above prints)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

import java.util.Scanner;

public class LabProgram {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int n = sc.nextInt();
// Validating the input
if(n >= 20 && n <= 98) {
// Running the countdown
while(true) {
System.out.print(n + " "); // Displaying the current value of the countdown
// If the digits are the same,
if(areDigitsIdentical(n)) {
break; // Breaking out from the loop
}
// Decreasing the value of the countdown
n--;
System.out.println("");
}
} else {
System.out.println("Input must be 20-98"); // Displaying the appropriate message for InValid Input
}
}

public static boolean areDigitsIdentical(int n) {
int d0 = n % 10; // Extracting out the 1st digit
int d1 = n / 10; // Extracting out the 2nd digit
// If the two digits are the same,
if(d0 == d1)
return true; // Return true
else // Otherwise,
return false; // Return false
}
}

 

The language is Java. The output has to print a space after each number including the last one (The pictures shown is what the code needs to print as well as what the code above prints)

Input
93
93
92 -
91 -
Your output
90 -
89 -
88
Expected out
93 92 91 90 89 88 e
2: Compare output ^
Output is nearly correct; but whitespace differs. See highlights below.
Special character legend
Input
77
Your output
77
Expected output
77 -
Transcribed Image Text:Input 93 93 92 - 91 - Your output 90 - 89 - 88 Expected out 93 92 91 90 89 88 e 2: Compare output ^ Output is nearly correct; but whitespace differs. See highlights below. Special character legend Input 77 Your output 77 Expected output 77 -
Input
20
20
19
18
17
16 -
Your output
15
14
13
12 +
11
Expected output
20 19 18 17 16 15 14 13 12 11
4: Compare output a
Input
99
Your output
Input must be 20-98
5: Compare output a
Input
19
Your output
Input must be 20-98
Transcribed Image Text:Input 20 20 19 18 17 16 - Your output 15 14 13 12 + 11 Expected output 20 19 18 17 16 15 14 13 12 11 4: Compare output a Input 99 Your output Input must be 20-98 5: Compare output a Input 19 Your output Input must be 20-98
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 10 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education