whats wrong with this program?/**Ex25.java* Ex25-To accept a three-digit number * and display the digit each on a single line,* and the sum of these digits.*@author *@version Oct.14.2010*/import java.awt.*;import java.util.Scanner;public class Ex25{p

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/27 13:43:05
whatswrongwiththisprogram?/**Ex25.java*Ex25-Toacceptathree-digitnumber*anddisplaythedigiteachonasing

whats wrong with this program?/**Ex25.java* Ex25-To accept a three-digit number * and display the digit each on a single line,* and the sum of these digits.*@author *@version Oct.14.2010*/import java.awt.*;import java.util.Scanner;public class Ex25{p
whats wrong with this program?
/**Ex25.java
* Ex25-To accept a three-digit number
* and display the digit each on a single line,
* and the sum of these digits.
*@author
*@version Oct.14.2010
*/
import java.awt.*;
import java.util.Scanner;
public class Ex25
{
private String hundredDigit,tenDigit,digit;
private int hd,td,d;
private double n;
private double sum,s;
public Ex25()
{
hundredDigit=getHundredDigit();
tenDigit=getTenDigit();
digit=getDigit();
hd();
td();
d();
sum();
}
public int getHundreDigit()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the hundredDigit:");
hundredDigit=sc.nextLine();
hd=Integer.parseInt(hundredDigit);
return hd;
}
public int getTenDigit()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the tenDigit:");
tenDigit=sc.nextLine();
td=Integer.parseInt( tenDigit);
return td;
}
public int getDigit()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the digit:");
digit=stdin.readLine();
d=Integer.parseInt(digit);
return d;
}
public void hundredigit()
{
hd=n/100;
System.out.println("The hundredDigit is:");
}
public void TenDigit()
{
td=((tn1*10)+(sn*1))/10;
System.out.println("The tensDigit is:");
}
public void Digit()
{
d=(n/100)%10;
System.out.println("The digit is:");
}
public void sum()
{
s=hd+td+d;
System.out.println("The hundredDigit is "+hd+"the tenDigit is "+td+"the digit is "+d+"The sum is:");
}
public static void main(String[]args)
{
Ex25 ex25=new Ex25();
}
}

whats wrong with this program?/**Ex25.java* Ex25-To accept a three-digit number * and display the digit each on a single line,* and the sum of these digits.*@author *@version Oct.14.2010*/import java.awt.*;import java.util.Scanner;public class Ex25{p
/**Ex25.java
* Ex25-To accept a three-digit number
* and display the digit each on a single line,
* and the sum of these digits.
*@author
*@version Oct.14.2010
*/
import java.awt.*;
import java.util.Scanner;
public class Ex25
{
private String hundredDigit,tenDigit,digit;
private int hd,td,d;
private double n;
private double sum,s;
public Ex25()
{
hundredDigit=getHundredDigit();
tenDigit=getTenDigit();
digit=getDigit();
Hundredigit();
TenDigit();
Digit();
sum();
}
public int getHundreDigit()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the hundredDigit:");
hundredDigit=sc.nextLine();
hd=Integer.parseInt(hundredDigit);
n+=hd*100;
return hd;
}
public int getTenDigit()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the tenDigit:");
tenDigit=sc.nextLine();
td=Integer.parseInt( tenDigit);
n+=td*10;
return td;
}
public int getDigit()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the digit:");
digit=stdin.readLine();
d=Integer.parseInt(digit);
n+=d;
return d;
}
public void Hundredigit()
{
hd=n/100;
System.out.println("The hundredDigit is:");
}
public void TenDigit()
{
td=n/10-hd*10;
System.out.println("The tensDigit is:");
}
public void Digit()
{
d=n%10;
System.out.println("The digit is:");
}
public void sum()
{
s=hd+td+d;
System.out.println("The hundredDigit is "+hd+"the tenDigit is "+td+"the digit is "+d+"The sum is:");
}
public static void main(String[]args)
{
Ex25 ex25=new Ex25();
}
}
The name of function you declare and call is not the same.
You don't initialize n when user input the three numbers.
Don't use a same name for both function and variable,it will cause an error.