Computer Science, asked by IntelligentBrain, 24 days ago

WRITE A PROGRAM to enter a three digit number and display the digit presenting one’s place, ten’s place and hundred’s place.

Answers

Answered by answerQueen53
0

Hope it will be helpful to you

ANSWERED BY ANSWER QUEEN

Attachments:
Answered by saitejasvikn
0

Answer:

import java.util.Scanner;

public class ValueOfDigits {

public static void main(String[] args) {

//Create new scanner

Scanner input = new Scanner(System.in);

//Values of each digit

int hundreds = 0;

int tens = 0;

int ones = 0;

//Prompt user to input 3 digit number

System.out.print("Enter a 3 digit number: ");

int number = input.nextInt();

//Displays hundreds place digit

hundreds = number / 100;

System.out.printf("Hundreds place digit: " , hundreds);

//Displays tens digit

tens = (number - hundreds) / 10;

System.out.printf("\nTens place digit: " , tens);

//Display ones digit

ones = (number - tens - hundreds);

System.out.printf("\nOnes place digit: " , ones);

//Error if number is less or more then three digits

if (number > 999);

System.out.println("\nError! Number more then 3 digits.");

if (number < 100);

System.out.println("Error! Number less then 3 digits.");

}

}

Similar questions