::ภาษา JAVA::...++การบ้าน lab4 credit พี่เอกห้อง 2 ++...
public class lab4_1 { public static void main(String[] args) { int x,y; for (x=1;x<=6 ;x++ ) { for (y=1;y<=x ;y++ ) { System.out.print("*"); } System.out.println(); } } }
-----------------------------------------------------------------------------
import javax.swing.JOptionPane; public class lab4_2 { public static void main(String[] args) { String input = JOptionPane.showInputDialog(null,"Enter number"); int x = Integer.parseInt(input); int by; int count = 0; for (by = 1; by <=x; by++ ) { if (x%by == 0) { //System.out.println(by); count++; } } if (count == 2) { JOptionPane.showMessageDialog(null,x+" is prime"); } else { JOptionPane.showMessageDialog(null,x+" is not prime"); } } }
-----------------------------------------------------------------------------
public class lab4_3 { public static void main(String[] args) { int i = 1; int j = 1; int k = 0; System.out.println(i); System.out.println(j); while ( k < 30) { k = i + j ; System.out.println(k); i = j; j = k; } } }
----------------------------------------------------------------------------
public class lab4_4 { public static void main(String[] args) { int count = 0; for (int x = 0; x < 50; x++ ) { System.out.println("Count is"+count); count++; } } }
-----------------------------------------------------------------------------
import java.util.Scanner; public class lab4_5 { public static void main(String[] args) { int guess; int count = 0; Scanner scan = new Scanner(System.in); System.out.println("t*****************nWelcome to the Guessing Gament*****************"); int number = (int)(Math.random()*10); System.out.println(number); do { System.out.print("Enter an int form 1 to 10 : "); guess = scan.nextInt(); count++; if (guess != number) { System.out.println("Try again..."); } } while (guess != number);
System.out.println("Number is "+number+"nYou win after "+count+" guesses."); } }
-----------------------------------------------------------------------------
Create Date : 16 กรกฎาคม 2551 |
|
0 comments |
Last Update : 16 กรกฎาคม 2551 13:47:40 น. |
Counter : 976 Pageviews. |
|
|
|