每次我尝试编译我的代码时,我都会收到关于缺少返回语句的错误。关于我的代码有什么问题的任何想法?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx So i fixed a couple of things, but now im getting an error where my variable 'result' might not have been initialized, any suggestions?
import javax.swing.JOptionPane;
import java.io.*;
public class facts
{
public static void main(String[]args)
{
String input;
int x;
char y,prime,perfect;
do{
input = JOptionPane.showInputDialog("Enter an integer");
x = Integer.parseInt(input);
if(x%2==0)
System.out.println("The integer is even - it is evenly divisible by 2");
else
System.out.println("The integer is not even - it is not evenly divisible by 2");
prime = isPrime(x);
if(prime == 't')
System.out.println("The integer is a prime number");
else
System.out.println("The integer is not a prime number");
perfect = isPerfect(x);
if(perfect == 't')
System.out.println("The integer is a perfect number");
else
System.out.println("The integer is not a perfect number");
input = JOptionPane.showInputDialog("Enter Y for another number, anything else to quit");
y = input.charAt(0);
}while(y=='Y');
System.out.println("Good Bye");
System.exit(0);
}
public static char isPrime(int x)
{
for(int y=2;y<x;y++)
{
if(x%y==0)
return 't';
else
return 'f';
}
}
public static char isPerfect(int x)
public static int triAng(int x)
{
int result,z,y = 1;
while(y<=x)
{
z=y*(y+1)/2;
y++;
System.out.println(z);
result = z;
}
return result;
}