226k views
4 votes
You can get the last digit of a positive integer n as n % 10. Complete the following program to compute the second-to-last digit. For example, if n is 1729, your program should print 2. If n is less than 10, print o. Complete the following file: SecondToLast.java import java.util.Scanner; 1 2 3 4 5 6 7 8 9 10 11 12 13 public class SecondToLast { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Radius: "); int n = in.nextInt(); double secondToLast = ...; System.out.println("Second to last digit: " } } + secondToLast); Submit

User Wolfram
by
8.0k points

1 Answer

4 votes

Answer: First, the last digit of the number is `n = n % 10`, once you have calculated the last digit of the number, the second last digit is `n = n % 10`.

Second, if n < 10 then print "o"

User Sandhya Agarwal
by
8.1k points