ช่วยดูโค้ด 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:
]
|