我是一個全新的java學生,我一直在搜索谷歌和我的教科書,弄清楚究竟是什麼意思,使用私有靜態布爾值,但沒有一個是真的有任何意義,所以我想我會問專家。我的問題是我需要使用私有靜態類,儘管我不知道如何從main(我的教授已經寫好)繪製需要的數據。你有什麼建議或見解?我基本上是將已經以嵌套循環形式寫入的代碼轉換爲私有類。使用私有靜態布爾
編輯: 這是我有(我不是在尋找施捨)
import java.io.*;
import java.util.*;
public class Foo
{
public static void main (String[] args) throws Exception
{
int lo = 0;
int hi = 0;
String infileName;
if (args.length < 3)
{
System.out.println("CMD LINE INPUT ERROR: Must enter 2 numbers followed by name of input file on cmd line.");
System.exit(0);
}
lo = Integer.parseInt(args[0]);
hi = Integer.parseInt(args[1]);
infileName = args[2];
for(int n = lo; n<=hi; n++)
if (isPrime(n))
System.out.print(n + " ");
System.out.println();
for(int n=lo; n<=hi; n++)
if (isPerfect(n))
System.out.print(n + " ");
System.out.println();
while (infile.ready())
{
String line = infile.readLine();
if (isPalindrome(line))
System.out.println(line + " IS a palindrome");
else
System.out.println(line + "is NOT a palindrome");
}
infile.close();
}
}
分配在三個部分的工作:尋找素數,完全數,和迴文。 的第1部分的例子,我以前使用以下找到素數
for(int i= lo; i < hi; i++)
{
boolean isPrime = true;
for(int j=2; j < i ; j++)
{
if(i % j == 0)
{
isPrime = false;
break;
}
}
if(isPrime)
System.out.print(i + " ");
}
System.out.println();
我大多不知道如何申請什麼我已經知道一種新的方式。
請張貼代碼和一點點具體談談這個問題。 –
是的,我們需要更多的信息來幫助你。我不知道人們如何回答這個問題。 – arshajii
你的意思是私有靜態方法? cuz私人靜態課程不可能是真的 – PermGenError