write a java code to extract middle digit of a number
Answers
public class prog
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,mid;
String s;
System.out.print("enter number:- ");
n=sc.nextInt();
s=n;
mid=Integer.parseInt(s.charAt(s.length()/2));
}
}
Answer:
class Mid
{
public static void main(int no)
{
int dno = no;
int noOfDigits = 0;
while(a!=0)
{
a = a/10;
noOfDigits++;
}
int first = 0;
int last = noOfDigits-1;
int middle = (first+last)/2;
boolean midExists = ((a1%2)==1);
System.out.println(" digits: "+a1);
int first = 0;
int last = noOfDigits-1;
int middle = (first+last)/2;
boolean midExists = ((a1%2)==1);
System.out.println(" digits: "+a1);
System.out.println(" no of digits "+noOfDigits);
System.out.println(" first "+first);
System.out.println(" last " + last);
if(midExists)
{
System.out.println(" middle " + middle);
int i = last;
int middleDigit = 0;
a = a1;
while(i != middle)
{
a = (a / 10);
middleDigit = (a%10);
i--;
}
System.out.println("middle digit: " + middleDigit);
}
else
System.out.println(" Mid not Exists.. ");
Explanation:
Pls mark my answer as the brainlest answer and pls follow me