栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

2021-10-05

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021-10-05

Java零基础学习02(有C语言基础)

本章主要熟练使用Scanner输入数据,通过练习课本带星课后题熟练java常见运算符的使用。

文章目录
  • Java零基础学习02(有C语言基础)

import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter the subtotal and a gratuity rate:");
        
        
        double subtotal=input.nextDouble();
        double rate=input.nextDouble(); 
        double srate=subtotal*rate*0.01;
        double total=subtotal+srate;
        System.out.println("The gratuity is $1.5 and total is $"+total);

    }
}

import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter a number between 0 and 1000 :");

        
        int number=input.nextInt();
        int a=number%10;
        int b=number/10;
        int c=b/10;
        int d=b-c*10;
        int sum=a+c+d;

        System.out.println("The sum of the digits is "+sum);

    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter the number of minutes :");

        
        double number=input.nextDouble();
        double yeartotal=number/365/24/60;
        int year=(int)yeartotal;
        double daytotal=365*(yeartotal-year);
        int day=(int)daytotal;

        
        System.out.println(number+"minutes is approximately "+year+"years and "+day+"days");

    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter the time zone offset to GMT : ");
        long zone=input.nextLong();
        long totalMilliseconds=zone*60*60*1000;
        long totalMillisecondsGMT=System.currentTimeMillis();
        long totalMiSecondes=totalMillisecondsGMT-(totalMilliseconds);
        long totalseconds=totalMiSecondes/1000;
        
        long seconds=totalseconds%60;
        long miniters=totalseconds/60%60;
        long hours=totalseconds/60/60%60;
        
        System.out.println("The current time is "+hours+":"+miniters+":"+seconds);

    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter the monthly saving amount : ");
        double samount=input.nextDouble();
        double total=0;
        for(int i=0;i<6;i++) {
            total = (samount + total) * (1 + 0.00417);
            System.out.println("After the sixth month,the account value is $" + total);
        }
    }
}

import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter weight in pounds : ");
        double weight=input.nextDouble();
        System.out.print("Enter height in pounds : ");
        double height=input.nextDouble();
        double bmi=(weight*0.45359237)/Math.pow(height*0.0254,2);
       System.out.println("BMI is "+bmi);
    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter the temperature in Fahrenheit between -58F and 41F : ");
        double ta=input.nextDouble();
        System.out.print("Enter the wind speed(>=2)in miles per hour : ");
        double v=input.nextDouble();
        double twc=35.74+0.6215*ta-35.75*Math.pow(v,0.16)+0.4275*ta*Math.pow(v,0.16);
       System.out.println("The wind chill index is "+twc);
    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter the coordinates of three points separated by spaces like x1,y1,x2,y2,x3,y3 : ");
        double x1=input.nextDouble();
        double y1=input.nextDouble();
        double x2=input.nextDouble();
        double y2=input.nextDouble();
        double x3=input.nextDouble();
        double y3=input.nextDouble();

        double s1=Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2));
        double s2=Math.sqrt(Math.pow((x3-x1),2)+Math.pow((y3-y1),2));
        double s3=Math.sqrt(Math.pow((x3-x2),2)+Math.pow((y3-y2),2));

        double s=(s1+s2+s3)/2;
        double a=s*(s-s1)*(s-s2)*(s-s3);
        double area=Math.pow(a,0.5);
       System.out.println("The area of the triangle is "+area);
    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter balance and interest rate(e.g.,3 for 3%: ");
        double balance=input.nextDouble();
        double rate=input.nextDouble();
        double interest=balance*(rate/1200);

       System.out.println("The interest is "+interest);
    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter investment amount: ");
        double amount=input.nextDouble();
        System.out.print("Enter annual interest rate in percentage: ");
        double rate=input.nextDouble();
        System.out.print("Enter number of year: ");
        double number=input.nextDouble();
        double fvalue=amount*Math.pow((1+rate/1200),(number*12));

       System.out.println("Future value is $"+fvalue);
    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter an amount in int,for example,1156 : ");
        int amount=input.nextInt();

        int numberOfOneDollars=amount/100;
        int remainingAmount=amount%100;
        int numberOfQuarters=remainingAmount/25;
        int numberOfDimes=remainingAmount%25/10;
        remainingAmount=remainingAmount%10;
        int numberOfNickels=remainingAmount/5;
        remainingAmount=remainingAmount%5;
        int numberOfPennies=remainingAmount;

        System.out.println("Your amount"+amount+"consist of");
        System.out.println(" "+numberOfOneDollars+"dollars");
        System.out.println(" "+numberOfQuarters+"quarters");
        System.out.println(" "+numberOfDimes+"dimes");
        System.out.println(" "+numberOfNickels+"nickels");
        System.out.println(" "+numberOfPennies+"pennies");
    }
}
import java.util.Scanner;

public class Java_1 {
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
        System.out.print("Enter the driving distance : ");
        double drivingDistance=input.nextDouble();
        System.out.print("Enter miles per gallon : ");
        double miles=input.nextDouble();
        System.out.print("Enter price per galoon: ");
        double price=input.nextDouble();

        double cost=(drivingDistance/miles)*price;

        System.out.println("The cost of driving is $"+cost);

    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/295151.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号