Computer Programming

  • Uploaded by: Bank
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Computer Programming as PDF for free.

More details

  • Words: 687
  • Pages: 9
MR.MAMPAN SANGSA 50052535

วิชา ข้อที่

Computer Programming

1)

โค้ดทีไ ่ ด้ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TestArray1 { /** * @param args */ public static void main(String[] args) { BufferedReader datain = new BufferedReader(new InputStreamReader( System.in)); String animal = ""; System.out.println("Please write name animal :" + animal);

try {

animal = datain.readLine(); } catch (IOException e) { System.out.println("Error!"); } // Display the name System.out.println("Name is " + animal + "!"); String sex = ""; System.out.println("Please enter animal sex :" + sex); try { sex = datain.readLine(); } catch (IOException e) { System.out.println("Error!"); } // Display the name System.out.println("Sex is " + sex + "!"); System.out.println("Please Enter name animal :"); // Read entered data into age variable //try..catch is used for protection the program try { animal = datain.readLine(); } catch (IOException e) { System.out.println("Error!"); } // Display the name System.out.println("Name is " + animal + "!"); String sex1 = ""; System.out.println("Please enter animal sex :" + sex1); try { sex1 = datain.readLine(); } catch (IOException e) { System.out.println("Error!"); } // Display the name System.out.println("Sex is " + sex1 + "!"); } }

ผลลัพธ์ของโปรแกรม Please write name animal : Dog Name is Dog! Please enter animal sex : Male Sex is Male! Please Enter name animal : Cat Name is Cat! Please enter animal sex : Female

Sex is Female!

ข้อที2 ่

โค้ดทีด ่ ้ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TestF3 { /** * @param args */ public static void main(String[] args) { BufferedReader datain = new BufferedReader(new InputStreamReader( System.in)); String Money = ""; System.out.println("Please your money is :" + Money); try { Money = datain.readLine(); } catch (IOException e) {

System.out.println("Error!"); } System.out.println("I have money is :" + Money + "Bath."); String Money1 = ""; System.out.println("What do you need ? " + Money1); try { Money1 = datain.readLine(); } catch (IOException e) { System.out.println("Error!"); } System.out.println("You need money is :" + Money1 + "Bath"); System.out.println("Thank you" + "!"); } }

ผลลัพธ์ของโปรแกรม Please your money is : 500 I have money is :500Bath. What do you need ? 400 You need money is :400Bath Thank you!

ข้อที3 ่

โค้ดทีไ ่ ด้ public class TestFor { /** * @param args */ public static void main(String[] args) { for (int count=0; count<=6; count++){ if (count!=5){ System.out.println(count); } else break; } System.out.println("End for"); } }

ผลลัพธืของโปรแกรม

0 1 2 3 4 End for

ข้อที4 ่

โค้ดทีไ ่ ด้ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TestStudent { /** * @param args */ public static void main(String[] args) { BufferedReader datain = new BufferedReader(new InputStreamReader(

System.in)); String name = ""; System.out.println("Please enter your name is :"); try { name = datain.readLine(); } catch (IOException e) { System.out.println("Error!"); e.printStackTrace(); return; } System.out.println("My name is :" + name); String age = ""; System.out.println("Please enter your age is :"); try { age = datain.readLine(); } catch (IOException e) { System.out.println("Error!"); e.printStackTrace(); return; } System.out.println("My age is :" + age + "ปี "); BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in)); String str_piont = null; System.out.println("Please your pionts is :"); try { str_piont = dataIn.readLine(); } catch (IOException e) { System.out.println("Error!"); e.printStackTrace(); return; } float points = Float.parseFloat(str_piont); System.out.println("Your pionts is :" + points + "คะแนน"); char grade = 0; if ((points >= 80) && (points <= 100)) { grade = 'A'; } else if ((points >= 70) && (points <= 79)) { grade = 'B'; } else if ((points >= 55) && (points <= 69)) { grade = 'C'; } else if ((points >= 40) && (points <= 54)) { grade = 'D'; } else if ((points >= 0) && (points <= 40)) { grade = 'F'; } else { return; } System.out.println("Your grade is :" + grade); } }

ผลลัพธ์ของโปรแกรม Please enter your name is : John My name is :John Please enter your age is : 15 My age is :15ปี Please your points is : 80 Your points is :80.0คะแนน Your grade is :A

ข้อที5 ่

โค้ดทีไ ่ ด้ public class TestWhile { /**

* @param args */ public static void main(String[] args) { int i=0; while (i<10){ System.out.println(i+","); i++; } System.out.println(i+","); } }

ผลลัพธ์ของโปรแกรม 0,1,2,3,4,5,6,7,8,9,10,

Related Documents


More Documents from "Bank"

Aim Star
June 2020 19
June 2020 18
June 2020 17