Answer the question
In order to leave comments, you need to log in
Wrote a method that finds the middle character of a number. Why doesn't the method return a.charAt(d)?
package com.company;
import java.util.Scanner;
public class Exercise_3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Введите число");
String a=sc.nextLine();
Number(a);
}
public static String Number(String a) {
if (a.length() % 2 != 0) {
int d = a.length() / 2 + 1;
return a.charAt(d);
} else {
int d = a.length() / 2 - 1;
return (a.substring(d, d + 2));
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question