DOC

Java

By Scott Stewart,2014-05-16 22:54
15 views 0
Java

Java作业

    2.3

    import java.util.Scanner;

    public class sumDifferenceProduct {

     public static void main(String[] args) {

     float x,y,sum,difference,product;

     Scanner in = new Scanner(System.in);

     System.out.println("please input two numbles.");

     x=in.nextFloat();y=in.nextFloat();

     sum = x + y ;difference = x - y ;product = x * y ;

     System.out.println(" sum = "+ sum );

     System.out.println(" difference = "+ difference );

     System.out.println(" product = "+ product );

     }

}

    2.4

    import java.util.Scanner;

    public class TempConverter {

     public static void main(String[] args) {

     final int BASE = 32 ;

     final double CONVERSION_FACTOR = 9.0/ 5.0 ;

     double fahrenheitTemp;

     int celsiusTemp ;

     Scanner in = new Scanner(System.in);

     System.out.println("please input .");

     celsiusTemp = in.nextInt();

     fahrenheitTemp = celsiusTemp * CONVERSION_FACTOR +

    BASE;

     System.out.println("Celsius Temperature :" + celsiusTemp);

     System.out.println("Fahrenheit Epuivalent :" + fahrenheitTemp);

     }

}

    2.5

    import java.util.Scanner;

    public class milesToKilometers {

     public static void main(String[] args) {

     float miles,kilometers;

     final double M = 1.60935;

     Scanner in = new Scanner(System.in);

     System.out.println("please input miles");

     miles = in.nextFloat();

     kilometers = (float)(M * miles);

     System.out.println(miles+"miles"+kilometers+"kilometers");

     }

}

    2.6

import java.util.Scanner;

    public class switchToseconds {

     public static void main(String[] args) {

     int seconds;

     Scanner in = new Scanner(System.in);

     System.out.print("hours:");

     int hours = in.nextInt();

     System.out.print("minutes:");

     int minutes = in.nextInt();

     System.out.print("seconds1:");

     int seconds1 = in.nextInt();

     seconds = hours * 3600 + minutes * 60 + seconds1;

     System.out.print("seconds:"+seconds);

     }

}

    2. 7

    import java.util.Scanner;

    public class switchHourMinutesSeconds {

     public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     System.out.print("please input seconds:");

     long seconds1 = in.nextInt();

     int hours =(int) (seconds1 / 3600) ;

     int minutes = (int)((seconds1 % 3600)/60);

     int second = (int)((seconds1 %3600)%60);

     System.out.println("hours:"+hours);

     System.out.println("minutes:"+minutes);

     System.out.println("second:"+second);

     }

    }

    2.9

    import java.util.Scanner;

    public class toSwitchMoney {

     public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     System.out.print("please input money:");

     float money = in.nextFloat();

     int ten = (int)(money/10);

     int five = (int)((money%10)/5);

     one = (int)((money%10)%5); int

     int quarters = (int)(((money*10)%10)/5)*2;

     int dimes = (int)(((money*10)%10)%5);

     int nickles = (int)(((money*100)%10)/5);

     int pennies = (int)(((money*100)%10)%5);

     System.out.println(money+" : ");

     System.out.println(ten+" ten dollar bills ");

     System.out.println(five+" five dollar bills ");

     System.out.println(one+" one dollor bills ");

     System.out.println(quarters+" quarters ");

     System.out.println(dimes+" dimes ");

     System.out.println(nickles+" nickles ");

     System.out.println(pennies+" pennies ");

     }

}

    2.11

    import java.util.Scanner;

    public class fraction {

     public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     System.out.print("please input numerator:");

     int numerator = in.nextInt();

     System.out.print("please input denommator:");

     int denommator = in.nextInt();

     double integers = (double)numerator/denommator ;

     System.out.print("integers:"+integers);

     }

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com