two Java problems
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/18 01:08:13
two Java problems
Question:Write a program which asks the user two numbers and the calculation (+, - , * or /) to be performed. The program shall print the calculation as well as the answer. Take care of the situation the divisor being zero.
My answer:
import java.util.Scanner;
public class task5 {
public static void main(String[] args) {
Scanner stdin=new Scanner(System.in);
System.out.println("Please enter a number ");
double a=stdin.nextDouble();
System.out.println("Please enter a number again");
double b=stdin.nextDouble();
String readEnter=stdin.nextLine();
System.out.println("Please enter a calculation(+-*/)");
String c=stdin.nextLine();
stdin.close();
String P="+", M="-", MU="*",D="/";
double result=0;
char cc=c.charAt(0);
if(cc.equals(P)){
result=a+b;
System.out.println("The result for "+a+c+b+" is "+result);
}
if(cc.equals(M)){
result=a-b;
System.out.println("The result for "+a+c+b+" is "+result);
}
if(cc.equals(MU)){
result=a*b;
System.out.println("The result for "+a+c+b+" is "+result);
}
if(cc.equals(D)){
if(b==0){
System.out.println("The divisor can not be 0.");
}
else{
result=a/b;
System.out.println("The result for "+a+c+b+" is "+result);
}
}
}
}
Why is it not correct?
The second one:
Question:Write a program which calculates and prints the discount table for a shop. The table is printed for the original prices from 10 euros to 100 euros with 5 euros interval. The discount percentage is asked from the user.
For example, if the user would enter 15 for the discount percent, the discount table should look as follows:
Original Price Cut-price (discount: 15%)
10 euros 8.5 euros
15 euros 12.75 euros
20 euros 17 euros
... ...
100 euros 85 euros
My answer:
import java.util.Scanner;
public class task6 {
public static void main(String[] args) {
Scanner stdin=new Scanner(System.in);
System.out.println("Please enter the discount: (IN %)");
String discountinpercent=stdin.nextLine();
double discount=Integer.parseDouble(discountinpercent);
double Rdiscount=discount/100;
System.out.println("Original Price Cut-price");
double price=10;
double cutdiscount=price*(1-Rdiscount);
while(price
Question:Write a program which asks the user two numbers and the calculation (+, - , * or /) to be performed. The program shall print the calculation as well as the answer. Take care of the situation the divisor being zero.
My answer:
import java.util.Scanner;
public class task5 {
public static void main(String[] args) {
Scanner stdin=new Scanner(System.in);
System.out.println("Please enter a number ");
double a=stdin.nextDouble();
System.out.println("Please enter a number again");
double b=stdin.nextDouble();
String readEnter=stdin.nextLine();
System.out.println("Please enter a calculation(+-*/)");
String c=stdin.nextLine();
stdin.close();
String P="+", M="-", MU="*",D="/";
double result=0;
char cc=c.charAt(0);
if(cc.equals(P)){
result=a+b;
System.out.println("The result for "+a+c+b+" is "+result);
}
if(cc.equals(M)){
result=a-b;
System.out.println("The result for "+a+c+b+" is "+result);
}
if(cc.equals(MU)){
result=a*b;
System.out.println("The result for "+a+c+b+" is "+result);
}
if(cc.equals(D)){
if(b==0){
System.out.println("The divisor can not be 0.");
}
else{
result=a/b;
System.out.println("The result for "+a+c+b+" is "+result);
}
}
}
}
Why is it not correct?
The second one:
Question:Write a program which calculates and prints the discount table for a shop. The table is printed for the original prices from 10 euros to 100 euros with 5 euros interval. The discount percentage is asked from the user.
For example, if the user would enter 15 for the discount percent, the discount table should look as follows:
Original Price Cut-price (discount: 15%)
10 euros 8.5 euros
15 euros 12.75 euros
20 euros 17 euros
... ...
100 euros 85 euros
My answer:
import java.util.Scanner;
public class task6 {
public static void main(String[] args) {
Scanner stdin=new Scanner(System.in);
System.out.println("Please enter the discount: (IN %)");
String discountinpercent=stdin.nextLine();
double discount=Integer.parseDouble(discountinpercent);
double Rdiscount=discount/100;
System.out.println("Original Price Cut-price");
double price=10;
double cutdiscount=price*(1-Rdiscount);
while(price
1、
String P="+",M="-",MU="*",D="/";
double result=0;
char cc=c.charAt(0);
if(cc.equals(P)){
result=a+b;
System.out.println("The result for "+a+c+b+" is "+result);
}
你cc是char,而P是String.所以把 char cc=c.charAt(0);换成:String cc=c.substring(0,1);
2.double discount=Integer.parseDouble(discountinpercent);
把Integer换成:Double
String P="+",M="-",MU="*",D="/";
double result=0;
char cc=c.charAt(0);
if(cc.equals(P)){
result=a+b;
System.out.println("The result for "+a+c+b+" is "+result);
}
你cc是char,而P是String.所以把 char cc=c.charAt(0);换成:String cc=c.substring(0,1);
2.double discount=Integer.parseDouble(discountinpercent);
把Integer换成:Double
TWO GRAMMAR PROBLEMS!
problems
There are two major problems linked with atomic power plants
my friend also has two other problems及翻译
1,Of the two problems,the first one is--.
英语完形填空Our world is facing many problems now.Two of the bigge
英语翻译There are two problems,then,in feeding the large number
英语口语话题讨论Find two enviromental problems in China,and point ou
Most of the problems in life are because of two reasons:we a
have problems
Physics problems.
maths problems!