여기에 제가 작성한 세 가지 프로그램이 있습니다. 하지만 작동하지 않습니다 ... 도와 주시겠습니까? 나는 인터넷을 통해 도움을 찾고 있었지만 아무 것도하지 않았다! 문제는 고급 기능을 사용할 수 없다는 것입니다. if 및 while을 사용하면 ... 왜 작동하지 않습니까? 여기에 프로그램은 : 당신이 Multiplying
, Adding
또는 Dividing
를 호출하기 전에3 개의 프로그램을 하나씩 넣고 싶은 사람에게 묻습니다.
import java.util.Scanner;
public class Threeinon {
public static void Adding (int A, int B)
{
int C, D;
if (A>0 && B>0)
{
C=A;
D=B;
while (D!=0) {
D=D-1;
C=C+1 ;
}
System.out.println("The summation is: " + C);
}
if (A>0 && B<0)
{
C=A;
D=B;
while (D!=0)
{
C=C-1;
D=D+1;
}
System.out.println("The summation is: " + C);
}
if (A<0 && B>0)
{
C=A;
D=B;
while (D!=0) {
C=C+1;
D=D-1;
}
System.out.println("The summation is: " + C);
}
if (A<0 && B<0)
{
C=A;
D=B;
while (D !=0)
{
C=C-1;
D=D+1;
}
System.out.println("The summation is: " + C);
}
}
public static void Multiplying (int A, int B)
{
int C, D;
if (A>0 && B>0)
{
C=0;
D=A;
while (D!=0){
D=D-1 ;
C=B+C;
System.out.println("The result is:" +C);
System.out.println("The second result is true.");
}
}
if (A==0)
{
System.out.println("The result is 0");
}
{
if (B==0)
{
System.out.println("The result is 0");
}
if (A<0)
{
C=0;
D=B;
while (D != 0) {
C=C+A;
D=D-1;
}
System.out.println("the result is:"+C);
}
if (B<0)
{
C=0;
D=A;
while (D != 0){
C=C+B;
D=D-1;
}
System.out.println("the result is:"+C);
}
if (A<0 && B<0)
{
C=0;
D=B;
while (D!=0){
C=A+C;
D=D+1;
System.out.println("the result is:" +C);
System.out.println("Only the first result is correct which is positive");
}
}
}
}
public static void Dividing (int A, int B)
{
int C, D;
if (A>0 && B>0){
C=0;
D=A;
while (D>=B){
D=D-B ;
C=C+1;
}
System.out.println("the result is:" + C);
}
if (A<0 && B>0)
{
C=0;
D=-A;
while (D>=B)
{
D=D-B;
C=C-1;
}
System.out.println("the result is:" +C);
}
if (A>0 && B<0)
{
C=0;
D=A;
while (D !=0)
{
C=C-1;
D=D+B;
}
System.out.println("the result is:" +C);
}
if (A<0 && B<0)
{
C=0;
D=-A;
while (D != 0)
{
D=D+B;
C=C+1;
}
System.out.println("the result is:" +C);
}
}
public static void main(String[] args){
int A=0, B=0;
int n;
Scanner scan = new Scanner(System.in);
System.out.println(" Enter 1 for multiplying");
System.out.println(" Enter 2 for adding");
System.out.println(" Enter 3 for dividing");
n= scan.nextInt();
if (n==1)
{
Multiplying (A, B) ;
}
else {
if (n==2)
{
Adding (A, B);
}
else {
if (n==3)
{
Dividing (A, B);
}
}
}
System.out.println("Ignore the two 0 you see, proceed");
System.out.println("Enter first number:");
A = scan.nextInt();
System.out.println("Enter second number:");
B = scan.nextInt();
Adding (A, B);
Multiplying (A,B);
Dividing (A, B);
}
}
왜 작동하지 않습니까? 결과가 예상치 못한 것이거나 오류가 있습니까? 오류가 발생하면 스택을 표시하고, 그렇지 않은 경우 결과가 올바르지 않으면 갖고있는 것과 원하는 것을 표시하십시오. –
프로그램에서 수행해야 할 작업은 무엇입니까? 더 자세한 설명을 주실 수 있습니까? –
"작동하지 않는다"는 것은 무엇을 의미합니까? 어떤 오류가 발생합니까? –