Pantip.com Pantip-TechExchange | Pantip-Cafe | PantipMarket.com | Chat | PanTown.com | BlogGang.com
 




ช่วยดูโค้ด java ให้ทีครับ เบื้องต้น if else

อาจจะมองเยอะ แต่เป็น Algorithms ง่ายๆ ช่วยดูทีครับ
import javax.swing.*;
class All
{
public static void main(String[] args)
{
All see = new All();
String s1,s2,str="",s3;
int a,b,p,d;
s2=JOptionPane.showInputDialog("Set Row Array ");
if(s2==null)
{
a=7;
str="User Cancel Or Not set value set array is 7";
JOptionPane.showMessageDialog(null,str,"Message",JOptionPane.INFORMATION_MESSAGE);


}
else if(s2.equals(""))
{
a=7;
str="User Cancel Or Not ser value set array is 7";
JOptionPane.showMessageDialog(null,str,"Message",JOptionPane.INFORMATION_MESSAGE);

}
else if(true){
try
{
Integer.parseInt(s2);
b=Integer.parseInt(s2);
if(b>30)
{
a=5;
str="User Cancel Or Not ser value set array is 5";
JOptionPane.showMessageDialog(null,str,"Message",JOptionPane.INFORMATION_MESSAGE);

}
else{
if (b<2)
{
a=5;
str="Number Is not Prime is set 5 array";
JOptionPane.showMessageDialog(null,str,"Message",JOptionPane.INFORMATION_MESSAGE);

}
else if(b==2)
{
a=2;
JOptionPane.showMessageDialog(null,str,"Message",JOptionPane.INFORMATION_MESSAGE);

}
else if(b>2)
{
p=Prime(b);
a=p;
}
}
}

catch(NumberFormatException e)
{
a=7;
str="Not number is 7";
JOptionPane.showMessageDialog(null,str,"Message",JOptionPane.INFORMATION_MESSAGE);
}
System.out.println("array"+a);//ตั้งแต่บรรทัดนี้เหมือนมันไม่รู้จักตัวแปร a ไม่รู้เพราะอะไร }
int data[] = new int[a] ;//ทำให้ผมใส่ a เป็น array ไม่ได้
do{

d=Integer.parseInt(JOptionPane.showInputDialog("----------Main Menu----------\n =============================== \n 1.Set Value \n 2.Show Value \n 3.Summation Data\n 4.Show data \n 5.Exit"));
if(d==1)
setValue(data);

}while(d!=5);
}

public static int Prime(int c)
{
int r,temp;
for(int i=3,end = (int)Math.sqrt(c);i<=end;i+=2){
if (c % i == 0) {
r=5;
temp=r;
c=temp;
}
else {
r=c;
temp=r;
c=temp;
}
}
return c;
}
public static void setValue(int slot[])
{
for(int i=0;i<slot.length;i++)
{
slot[i]=1+(int)(Math.random()*12);
}
String str="create Array finish";
JOptionPane.showMessageDialog(null,str,"Message",JOptionPane.INFORMATION_MESSAGE);
}
}

ทำไงดีครับ มันไม่รู้จักตัวแปร a


จากคุณ : กบน้อย -[ 26 ธ.ค. 55 - 21:29:58 A:125.25.73.150 X: ]



Share/Save/Bookmark
แจ้งลบ ทดสอบแล้วใช้ได้ผล Bookmark ส่งต่อกระทู้ พิมพ์ โหวตกระทู้ ขอทราบด้วยคน ยกเลิกการแจ้งเมล์ เก็บเข้าคลังกระทู้ กระทู้ก่อนหน้า กระทู้ถัดไป




แจ้งลบ ทดสอบแล้วใช้ได้ผล Bookmark ส่งต่อกระทู้ พิมพ์ โหวตกระทู้ ขอทราบด้วยคน ยกเลิกการแจ้งเมล์ เก็บเข้าคลังกระทู้ กระทู้ก่อนหน้า กระทู้ถัดไป

คลิกเพื่อ ติดต่อทีมงาน ติชมแนะนำ หรือแจ้งปัญหาต่างๆ
คลิกเพื่ออ่าน กติกามารยาท
คลิกเพื่ออ่าน Help & FAQ

ชื่อ / e-mail :   ตรวจสอบสถานะ member ที่นี่
รูปประกอบ : ( ไม่เกิน 150 K / Member เท่านั้น / Preview ไม่ได้ )
รายละเอียด :
แจ้งทาง mail เมื่อมีผู้ตอบ : ไม่ต้องแจ้ง แจ้ง (E-mail ในกรณีต้องการให้แจ้ง)
 
 
 

ข้อความหรือรูปภาพที่ปรากฏในกระทู้ที่ท่านเห็นอยู่นี้ เกิดจากการตั้งกระทู้และถูกส่งขึ้นกระดานข่าวโดยอัตโนมัติจากบุคคลทั่วไป ซึ่ง PANTIP.COM มิได้มีส่วนร่วมรู้เห็น ตรวจสอบ หรือพิสูจน์ข้อเท็จจริงใดๆ ทั้งสิ้น หากท่านพบเห็นข้อความ หรือรูปภาพในกระทู้ที่ไม่เหมาะสม กรุณาแจ้งทีมงานทราบ เพื่อดำเนินการต่อไป
Considering the real-time nature of this webboard, it is impossible for us to review all messages/post. Please remember that we do not actively monitor the contents of and are not responsible for any messages posted. Anyone who feels that a posted message is inappropriate, Please encouraged to contact us immediately by email at kratoo@pantip.com , and We will remove objectionable messages within a reasonable time frame.



Pantip-Cafe | Pantip-TechExchange | PantipMarket.com | PanTown.com | BlogGang.com