Write a Program in Java to take a number as input then display the highest dighit it has...
Use following method prototype: int highest (int n)
import java.util.Scanner;
public class App {
private static int highest (int n) {
int max = 0;
while (n != 0)
{
int number=n % 10;
if(number>max) {
max = number;
}
n = n / 10;
}
return max;
}
public static void main(String[] args) {
int n = -1;
Scanner keyBoard = new Scanner(System.in);
while (n < 0 || n > 1000000)
{
System.out.print("Enter an integer between 0 and 1000000: ");
n = keyBoard.nextInt();
}
System.out.println("The highest digit is: "+highest(n));
keyBoard.close();
}
}
Comments
Dear Alex please post a new task
Can the programming be solved without using "static" keyword?
Leave a comment