practice1
import java.io.*;public class practice1{ public static void main(String[] args)throws IOException { BufferedReader keyin= new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter some numbers "); String numberString=keyin.readLine(); int number = Integer.parseInt(numberString.trim()); int answer=1; while(number > 0) { answer=answer*number; numberString = keyin.readLine(); number = Integer.parseInt(numberString.trim()); } System.out.println("sum is "+answer); }}
project3_7
import java.io.*;public class p3_7{public static void main(String[] args) throws IOException{BufferedReader keyin= new BufferedReader(new InputStreamReader(System.in));System.out.println("Please enter the number x of e^x");int x = Integer.parseInt(keyin.readLine());System.out.println("Please enter the number n ");int n = Integer.parseInt(keyin.readLine());double i,j,k=1,s,m=1,sum=0;for(i=0;i<=n;i++) { for(j=i;j>0;j--)k=k*j;for(s=i;s>0;s--)m=m*x;sum=sum+(m/k);}System.out.println("e^x = "+sum);}}
max_min
import java.io.*; import java.io.IOException; public class testmin { public static void main(String[] args) throws IOException { BufferedReader keybord = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter some numbers"); String inputString1 =keyboard.readLine(); int next1 = Integer.parseInt(inputString1); int theNumber=next1; int a[]={theNumber}; int i,j; for (i = 0; ; i++); System.out.println(a[i]); for (i = 0; ; i++); int k,temp,s; for (i = 0; ; i++){ s=0; for (j = 0; ; i++) { if(a[j]>a[j=+1]){ s=1; temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } if(s !=1) break; } System.out.println("the min is"+a[0]); System.out.println("the max is"+a[j+1]); } }
試了好久~~好像還是不太行
if else 154
import javax.swing.JOptionPane;public class display3_1{public static void main(String[] args) { String theNumber=JOptionPane.showInputDialog("Enter the number "); int number=Integer.parseInt(theNumber); if(number <>
System.out.println(number+"is less than zero.");
else if (number <>
System.out.println(number+"is between 0 and 99(inclusuve).");
else
System.out.println(number+"is 100 or large.");
System.exit(0);
}
}
project2_7
import javax.swing.JOptionPane;public class project2_7{ public static void main(String[] args) { String thePrice=JOptionPane.showInputDialog("Enter price of item\n"+"(from 25 cents to a dollar, in 5-cent increments):"); int price=Integer.parseInt(thePrice); System.out.println("You bought an item for "+price+" cents and gave me a dollar,\n"+"so your change is"); int change = 100 - price; int quarter=0,dime=0,nickel=0;if(change >= 25){ quarter = change / 25;change = change%25;}if(change>=10 && change <25) dime =" change/10;" change =" change%10;">=5 && change <10){ nickel = change/5;change = change%5;}if(change<0) { System.out.println("You should pay more money!!!"); } System.out.println(quarter+" quarters,"); System.out.println(dime+" dimes,and"); System.out.println(nickel+" nickels."); System.exit(0); }}
project2_5
import javax.swing.JOptionPane;public class project2_5{public static void main(String[] args){ String myPurchase=JOptionPane.showInputDialog("Enter the purchase price"); double purchaseprice = Integer.parseInt(myPurchase); String mySalvage =JOptionPane.showInputDialog("Enter the salvage value"); double salvagevalue = Integer.parseInt(mySalvage); String myYear = JOptionPane.showInputDialog("Enter the number of year"); double numberyear = Integer.parseInt(myYear); double d; d=(purchaseprice-salvagevalue)/numberyear; System.out.println("The value of the yearly depreciation is "+d);}}
IncomeTax
public class IncomeTax { public static void main(String[] args) { double netIncome=30000,tax,fivePercentTax,tenPercentTax; if(netIncome <=15000) tax=0; else if ((netIncome>15000)&&(netIncome<=30000)) tax=(0.05*(netIncome-15000)); else { fivePercentTax =0.05*15000; tenPercentTax=0.10*(netIncome-30000); tax=(fivePercentTax + tenPercentTax); } System.out.println("Tax due = "+ tax); } }
scannerDemo
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class scannerDemo { public static void main(String[] args) throws IOException { BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the number of pods followed by "); System.out.println("the number of peas in a pod:"); int numberOfPods =Integer.parseInt(keyboard.readLine()); int peasPerPod =Integer.parseInt(keyboard.readLine()); int totalNumberOfPeas = numberOfPods*peasPerPod; System.out.println(numberOfPods +" ponds and "); System.out.println(peasPerPod +" peas per pod ."); System.out.println("The total number of peas = " +totalNumberOfPeas ); } }
10/17上課練習程式
import javax.swing.JOptionPane;
public class test
{
public static void main(String[] args)
{
String myString=JOptionPane.showInputDialog("Enter a number");
int myNumber = Integer.parseInt(myString);
System.out.println("The number is "+ myNumber);
System.exit(0);
}
}
display1.7
display1.7程式碼public class StringProcess { public static void main(String[] args) { String sentence = " I hate text processing!"; int position =sentence.indexOf(" hate "); String ending= sentence.substring(position + " hate ".length() ); System.out.println("01234567890123456789012"); System.out.println(sentence); System.out.println(" The word \" hate \" atarts at index "+position); sentence=sentence.substring(0,position) + "adore" +ending; System.out.println("The changed string is: "); System.out.println(sentence); } }
project5
project 程式碼
public class project5 { public static void main(String[] args) { String sentence = " I hate you"; int position =sentence.indexOf(" hate "); String ending=sentence.substring(position+ "hate".length()); System.out.println("The line of text to be charged is:"); System.out.println(sentence); System.out.println("I have rephrased that line to read"); sentence=sentence.substring(0,position) + " love " + ending; System.out.println(sentence); } }
HW3
public class cal_hw3 { public static void main(String[] args) { System.out.println("we know "); System.out.println("running 6 MPH:10 METS "); System.out.println ("basketball:8 METS"); System.out.println ("sleeping:1METS"); System.out.println("The person is 150/2.2 Kg "); double w=150/2.2,cal_r,cal_b,cal_s,all; cal_r=0.0175*10*w*30; cal_b=0.0175*8*w*30; cal_s=0.0175*1*w*6*60; all=cal_r+cal_b+cal_s; System.out.println("The person is "+w+" Kg."); System.out.println("The person consumed "+cal_r+" Calories for running."); System.out.println("He consumed "+cal_b+" Calories for basketball."); System.out.println("He consumed "+cal_s+" Calories for sleeping."); System.out.println("The tatal number of calories he consumed is "+all+" ."); } }