「Java」カテゴリーアーカイブ

[java]
pacage jp.co.example.java15;

public class Main {
public static void main(String[] args){
for (int testNumber = 2; testNumber <= 100; testNumber++){
boolean isPrimeNumber = true;//mathtic
for (int i = 2; i < testNumber; i++) {
if(testNumber % i == 0) {
isPrimeNumber = false;
break;
}
}

  if (isPrimeNumber){ //functic
    System.out.println(testNumber);
  }
}

}
}


point
What is code ,what to do
be sure function


watch out valuable
boolean isPrimeNumber
int i
int testNumber

public class Main {
public static void main(String[] args){
for (int testNumber = 2; testNumber <= 100; testNumber++){
if (isPrimeNumber){
System.out.println(testNumber);
}
}
}
private static boolean isPrimeNumber(int testNumber){
for (int i = 2; i < testNumber; i++){
if(testNumber % i == 0){
return false;
}
}
return true;
}
}

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

public class Main {
public static void main(String[] args){
for (int testNumber = 2; testNumber <= 100; testNumber++){
boolean isPrimeNumber = isPrimeNumber(testNumber);
if (isPrimeNumber){
System.out.println(testNumber);
}
}
}
private static boolean isPrimeNumber(int testNumber){
for (int i = 2; i < testNumber; i++){
if(testNumber % i == 0){
return false;
}
}
return true;
}
}

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
//individaul
public class Main {
public static void main(String[] args){
for (int testNumber = 2; testNumber <= 100; testNumber++){//functic
if (isPrimeNumber(testNumber)){
System.out.println(testNumber);
}
}
}
private static boolean isPrimeNumber(int testNumber){//mathtic
for (int i = 2; i < testNumber; i++){
if(testNumber % i == 0){
return false;
}
}
return true;
}
}

/////////////////////////////
///
///
///
public class Main {
public static void main(String[] args){
//arrange Item
Item pencil = new Item("umi-hb-001","umi HB", "yotsubisienpitsu", "120");
//view Item
System.out.println("item");

//enpitu
System.out.println(&quot;itemCode&quot; + pencil.getCode());
System.out.println(&quot;itemname&quot; + pencil.getName());
System.out.println(&quot;itemmaker&quot; + pencil.getMaker());
System.out.println(&quot;itemPrice&quot; + pencil.getPrice());

}
}

///////////////////////////////
public class Item {
private final String code;
private final String name;
private final String maker;
private final int price;
public Item(String code, String name, String maker, int price){
super();
this.code = code;
this.name = name;
this.maker = maker;
this.price = price;
}
public String getCode(){
return code;
}
public String getName(){
return name;
}
public String getMaker(){
return maker;
}
public String getPrice(){
return price;
}
}
[/java]