在JAVA,输入一个正整数,求此正整数的中间数(比如12345的中间数是3,1234则没有中间数)
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/12 15:23:54
在JAVA,输入一个正整数,求此正整数的中间数(比如12345的中间数是3,1234则没有中间数)
题目是:The middle digit of an integer number (Middle, for short). For a positive number read from the standard input extract the digit in the middle and display it, if this exists; otherwise display “no middle digit”. For 145, the middle digit is 4, whereas in the case of 1324, there is no middle digit.
我自己编写了个程序,可以编译,可是一运行就出现错误,请帮我修改看看那里错了
//Display Enter an integer number in a message dialog box
String Integernumber = JOptionPane.showInputDialog("Enter an integer number:");
//Calculate how many figure in this integer number
String str1 = String.valueOf(Integernumber);
int str = Integer.parseInt(str1);
//determine the length of number isn't even.
int digit = str % 2;
if (digit == 0) {
String output = "There is no middle digit in "+Integernumber;
JOptionPane.showMessageDialog(null, output);
}
else {
double n = str / 2;
double n1 = n - 0.5;
double n2 = n + 0.5;
int n11 = (int)n1;
int n22 = (int)n2;
String middle = Integernumber.substring(n11,n22);
String output = "The middle digit in "+Integernumber+" is "+middle;
JOptionPane.showMessageDialog(null, output);
}
}
}
最好给我全部的代码,谢谢了
题目是:The middle digit of an integer number (Middle, for short). For a positive number read from the standard input extract the digit in the middle and display it, if this exists; otherwise display “no middle digit”. For 145, the middle digit is 4, whereas in the case of 1324, there is no middle digit.
我自己编写了个程序,可以编译,可是一运行就出现错误,请帮我修改看看那里错了
//Display Enter an integer number in a message dialog box
String Integernumber = JOptionPane.showInputDialog("Enter an integer number:");
//Calculate how many figure in this integer number
String str1 = String.valueOf(Integernumber);
int str = Integer.parseInt(str1);
//determine the length of number isn't even.
int digit = str % 2;
if (digit == 0) {
String output = "There is no middle digit in "+Integernumber;
JOptionPane.showMessageDialog(null, output);
}
else {
double n = str / 2;
double n1 = n - 0.5;
double n2 = n + 0.5;
int n11 = (int)n1;
int n22 = (int)n2;
String middle = Integernumber.substring(n11,n22);
String output = "The middle digit in "+Integernumber+" is "+middle;
JOptionPane.showMessageDialog(null, output);
}
}
}
最好给我全部的代码,谢谢了
import javax.swing.JOptionPane;
public class Test {
public static void main(String[] args){
String Integernumber = JOptionPane.showInputDialog("Enter an integer number:");
int len = Integernumber.length();
if(len % 2 == 0){
String output = "There is no middle digit in "+Integernumber;
JOptionPane.showMessageDialog(null,output);
} else {
char middle = Integernumber.charAt(len/2);
String output = "The middle digit in "+Integernumber+" is "+middle;
JOptionPane.showMessageDialog(null,output);
}
}
}
已经运行过了,没问题
public class Test {
public static void main(String[] args){
String Integernumber = JOptionPane.showInputDialog("Enter an integer number:");
int len = Integernumber.length();
if(len % 2 == 0){
String output = "There is no middle digit in "+Integernumber;
JOptionPane.showMessageDialog(null,output);
} else {
char middle = Integernumber.charAt(len/2);
String output = "The middle digit in "+Integernumber+" is "+middle;
JOptionPane.showMessageDialog(null,output);
}
}
}
已经运行过了,没问题
如果三个连续正整数,中间一个是平方数,将这样的三个连续正整数的积叫“幸运数”.
如果三个连续正整数,中间一个是平方数,将这样的三个连续正整数的积叫做幸运数.所有小于2007的幸运数的最
如果三个连续正整数,中间一个是平方数,将这样的三个连续正整数的积叫做“幸运数”.所有小于2007的 “幸运数”最小公倍数
有三个连续的四位正整数,中间一个为完全平方数,且三个数的和能被15整除,则中间的数的最小值是( )
三个连续正整数,中间一个数的九倍比其他两个数的积大于9,求这三个自然数?
有三个连续的四位正整数中间1个是完全平方数,且3数之和能被15整除,中间1数的最小值?
如果三个连续的正整数中间一个是平方数,将这样的三个连续正整数的积叫做幸运数,所有小于等于2011的幸运
三个连续正整数,中间一个完全是完全平方数,将这样的三个连续正整数的积称为“美妙数”,问所有小于2008
有三个连续的四位正整数,中间一个为完全平方数,且三个数的和能被15整除,则中间的数的最小值是______.
已知5个连续正整数的中间一个数为n,请你写出其余4个数.
已知五个连续正整数的中间一个数为n【↓为题】
如果有三个连续正整数中间是一个平方数将这样三个正整数的积叫做睿达数那么所有小于2013最大公因数