Answer to Question #260646 in Java | JSP | JSF for Alex

Question #260646

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)


1
Expert's answer
2021-11-03T11:44:12-0400
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();
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
05.11.21, 13:27

Dear Alex please post a new task


Alex
05.11.21, 10:07

Can the programming be solved without using "static" keyword?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS