急!java 程序!
发布网友
发布时间:2024-05-01 16:05
我来回答
共3个回答
热心网友
时间:2024-10-10 16:23
先写一个
import java.io.*;
public class demo{
public static void main(String[] args) throws IOException {
long num1,num2;
String str;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
num1=Long.parseLong(str);
str=br.readLine();
num2=Long.parseLong(str);
if(num1<num2){
long temp=num1;
num2=num1;
num1=temp;
}
long a=num1,b=num2;
while(b!=0){
long temp=a%b;
a=b;
b=temp;
}
System.out.println("最大公约数: "+a);
System.out.println("最小公倍数: "+num1*num2/a);
}
}
时间关系 部分是用汉语拼音!
我也是新手 有不对的地方请指教
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Untitled2 {
public static void main(String[] args) throws IOException {
float num;
int num_ge,num_shi,num_;
String str;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
do{
str = br.readLine();
num = Float.parseFloat(str);
if(num>5||num<0.1)
System.out.println("输入价格不在范围内,请重新输入!");
}
while(num>5||num<0.1);
System.out.println("您输入的数字是: "+num);
num=5-num;
if(num==0)System.out.println("不找钱!!");
else
{
System.out.println("应找钱为:");
num=num*100;
num_ge=(int)num%10;
num_shi=(int)num/10%10;
num_=(int)num/100;
if(num_!=0)
{
switch(num_)
{
case 1:System.out.print("一 元 1 张 ");break;
case 2:System.out.print("liang yuan 1 ge ");break;
case 3:System.out.print("yi yuan 1 ge liang yuan 1 ge ");break;
case 4:System.out.print("liang yuan 2 ge ");break;
}
}
if(num_shi!=0)
{
switch(num_shi)
{
case 1:System.out.print("一 角 1 个 ");break;
case 2:System.out.print("liang jiao 1 ge ");break;
case 3:System.out.print("yi jiao 1 ge liang jiao 1 ge ");break;
case 4:System.out.print("liang jiao 2 ge ");break;
case 5:System.out.print("whu jiao 1 ge ");break;
case 6:System.out.print("whu jiao 1 ge yi jiao 1 ge ");break;
case 7:System.out.print("whu jiao 1 ge liang jiao 1 ge ");break;
case 8:System.out.print("whu jiao 1 ge yi jiao 1 ge liang jiao 1 ge ");break;
case 9:System.out.print("whu jiao 1 ge liang jiao 2 ge ");break;
}
}
if(num_ge!=0)
{
switch(num_ge)
{
case 1:System.out.print("一 分 1 个 ");break;
case 2:System.out.print("liang fen 1 ge ");break;
case 3:System.out.print("yi fen 1 ge liang fen 1 ge ");break;
case 4:System.out.print("liang fen 2 ge ");break;
case 5:System.out.print("whu fen 1 ge ");break;
case 6:System.out.print("whu fen 1 ge yi fen 1 ge ");break;
case 7:System.out.print("whu fen 1 ge liang fen 1 ge ");break;
case 8:System.out.print("whu fen 1 ge yi fen 1 ge liang fen 1 ge ");break;
case 9:System.out.print("whu fen 1 ge liang fen 2 ge ");break;
}
}
}
}
}
我的qq150979313
热心网友
时间:2024-10-10 16:23
第二题有点小BUG,小数点后只有一位时总是会少0.01。比如输入0.1,0.2这样的值。
因为浮点数采用二进制表示,而二进制系统中无法精确表示1/10。要精确表示的话要用BigDecimal类。
第一题:
package net.pzw;
import java.util.Scanner;
public class MinAndMax {
public MinAndMax(int x,int y) {
int temp,a,b;
if(x<y){
temp=x;
x=y;
y=temp;
}
a=x;
b=y;
while(b!=0){
temp=a%b;
a=b;
b=temp;
}
System.out.println("两数最大公分子为:"+a);
System.out.println("两数最小公分母为:"+x*y/a);
}
public static void main(String[] args) {
int a,b;
Scanner scan=new Scanner(System.in);
System.out.print("请输入第一个数:");
a=scan.nextInt();
System.out.print("请输入第二个数:");
b=scan.nextInt();
new MinAndMax(a,b);
}
}
第二题:
package net.pzw;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Money {
private static final double FIVEYUAN=5.00;
private static final double TWOYUAN=2.00;
private static final double ONEYUAN=1.00;
private static final double FIFTHFENG=0.5;
private static final double TWENTYFENG=0.2;
private static final double TENFENG=0.1;
private static final double FIVEFENG=0.05;
private static final double TWOFENG=0.02;
private static final double ONEFENG=0.01;
public Money(double input) {
double money[]=new double[]{FIVEYUAN,TWOYUAN,ONEYUAN,FIFTHFENG,
TWENTYFENG,TENFENG,FIVEFENG,TWOFENG,ONEFENG};
double total=0,temp=money[0];
DecimalFormat myformat=new DecimalFormat("##.##");
for(int i=0;i<money.length;i++){
if(input>5||input<0.1){ System.out.println("请输入0.1-5间的数。");
break;
}
if(input==5){
System.out.println("刚好,不用找钱了。");
break;
}
if(temp-input>=money[i]){
do {
total=money[i];
System.out.println(total);
temp=temp-money[i];
temp=Double.parseDouble(myformat.format(temp));
} while (temp-input>money[i]);
}else{
continue;
}
}
}
static public void main(String[] args){
System.out.print("请输入一个数:");
Scanner scan=new Scanner(System.in);
double input=scan.nextDouble();
new Money(input);
}
}
热心网友
时间:2024-10-10 16:24
peizhengwen您好,谢谢您。您的程序其实已经很好了。我真的很谢谢您。我的qq:605489969,当然如果有时间能完善就更好了。-----happywebfish
热心网友
时间:2024-10-10 16:23
先写一个
import java.io.*;
public class demo{
public static void main(String[] args) throws IOException {
long num1,num2;
String str;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
num1=Long.parseLong(str);
str=br.readLine();
num2=Long.parseLong(str);
if(num1<num2){
long temp=num1;
num2=num1;
num1=temp;
}
long a=num1,b=num2;
while(b!=0){
long temp=a%b;
a=b;
b=temp;
}
System.out.println("最大公约数: "+a);
System.out.println("最小公倍数: "+num1*num2/a);
}
}
时间关系 部分是用汉语拼音!
我也是新手 有不对的地方请指教
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Untitled2 {
public static void main(String[] args) throws IOException {
float num;
int num_ge,num_shi,num_;
String str;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
do{
str = br.readLine();
num = Float.parseFloat(str);
if(num>5||num<0.1)
System.out.println("输入价格不在范围内,请重新输入!");
}
while(num>5||num<0.1);
System.out.println("您输入的数字是: "+num);
num=5-num;
if(num==0)System.out.println("不找钱!!");
else
{
System.out.println("应找钱为:");
num=num*100;
num_ge=(int)num%10;
num_shi=(int)num/10%10;
num_=(int)num/100;
if(num_!=0)
{
switch(num_)
{
case 1:System.out.print("一 元 1 张 ");break;
case 2:System.out.print("liang yuan 1 ge ");break;
case 3:System.out.print("yi yuan 1 ge liang yuan 1 ge ");break;
case 4:System.out.print("liang yuan 2 ge ");break;
}
}
if(num_shi!=0)
{
switch(num_shi)
{
case 1:System.out.print("一 角 1 个 ");break;
case 2:System.out.print("liang jiao 1 ge ");break;
case 3:System.out.print("yi jiao 1 ge liang jiao 1 ge ");break;
case 4:System.out.print("liang jiao 2 ge ");break;
case 5:System.out.print("whu jiao 1 ge ");break;
case 6:System.out.print("whu jiao 1 ge yi jiao 1 ge ");break;
case 7:System.out.print("whu jiao 1 ge liang jiao 1 ge ");break;
case 8:System.out.print("whu jiao 1 ge yi jiao 1 ge liang jiao 1 ge ");break;
case 9:System.out.print("whu jiao 1 ge liang jiao 2 ge ");break;
}
}
if(num_ge!=0)
{
switch(num_ge)
{
case 1:System.out.print("一 分 1 个 ");break;
case 2:System.out.print("liang fen 1 ge ");break;
case 3:System.out.print("yi fen 1 ge liang fen 1 ge ");break;
case 4:System.out.print("liang fen 2 ge ");break;
case 5:System.out.print("whu fen 1 ge ");break;
case 6:System.out.print("whu fen 1 ge yi fen 1 ge ");break;
case 7:System.out.print("whu fen 1 ge liang fen 1 ge ");break;
case 8:System.out.print("whu fen 1 ge yi fen 1 ge liang fen 1 ge ");break;
case 9:System.out.print("whu fen 1 ge liang fen 2 ge ");break;
}
}
}
}
}
我的qq150979313
热心网友
时间:2024-10-10 16:23
第二题有点小BUG,小数点后只有一位时总是会少0.01。比如输入0.1,0.2这样的值。
因为浮点数采用二进制表示,而二进制系统中无法精确表示1/10。要精确表示的话要用BigDecimal类。
第一题:
package net.pzw;
import java.util.Scanner;
public class MinAndMax {
public MinAndMax(int x,int y) {
int temp,a,b;
if(x<y){
temp=x;
x=y;
y=temp;
}
a=x;
b=y;
while(b!=0){
temp=a%b;
a=b;
b=temp;
}
System.out.println("两数最大公分子为:"+a);
System.out.println("两数最小公分母为:"+x*y/a);
}
public static void main(String[] args) {
int a,b;
Scanner scan=new Scanner(System.in);
System.out.print("请输入第一个数:");
a=scan.nextInt();
System.out.print("请输入第二个数:");
b=scan.nextInt();
new MinAndMax(a,b);
}
}
第二题:
package net.pzw;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Money {
private static final double FIVEYUAN=5.00;
private static final double TWOYUAN=2.00;
private static final double ONEYUAN=1.00;
private static final double FIFTHFENG=0.5;
private static final double TWENTYFENG=0.2;
private static final double TENFENG=0.1;
private static final double FIVEFENG=0.05;
private static final double TWOFENG=0.02;
private static final double ONEFENG=0.01;
public Money(double input) {
double money[]=new double[]{FIVEYUAN,TWOYUAN,ONEYUAN,FIFTHFENG,
TWENTYFENG,TENFENG,FIVEFENG,TWOFENG,ONEFENG};
double total=0,temp=money[0];
DecimalFormat myformat=new DecimalFormat("##.##");
for(int i=0;i<money.length;i++){
if(input>5||input<0.1){ System.out.println("请输入0.1-5间的数。");
break;
}
if(input==5){
System.out.println("刚好,不用找钱了。");
break;
}
if(temp-input>=money[i]){
do {
total=money[i];
System.out.println(total);
temp=temp-money[i];
temp=Double.parseDouble(myformat.format(temp));
} while (temp-input>money[i]);
}else{
continue;
}
}
}
static public void main(String[] args){
System.out.print("请输入一个数:");
Scanner scan=new Scanner(System.in);
double input=scan.nextDouble();
new Money(input);
}
}
热心网友
时间:2024-10-10 16:24
peizhengwen您好,谢谢您。您的程序其实已经很好了。我真的很谢谢您。我的qq:605489969,当然如果有时间能完善就更好了。-----happywebfish
热心网友
时间:2024-10-10 16:23
先写一个
import java.io.*;
public class demo{
public static void main(String[] args) throws IOException {
long num1,num2;
String str;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
num1=Long.parseLong(str);
str=br.readLine();
num2=Long.parseLong(str);
if(num1<num2){
long temp=num1;
num2=num1;
num1=temp;
}
long a=num1,b=num2;
while(b!=0){
long temp=a%b;
a=b;
b=temp;
}
System.out.println("最大公约数: "+a);
System.out.println("最小公倍数: "+num1*num2/a);
}
}
时间关系 部分是用汉语拼音!
我也是新手 有不对的地方请指教
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Untitled2 {
public static void main(String[] args) throws IOException {
float num;
int num_ge,num_shi,num_;
String str;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
do{
str = br.readLine();
num = Float.parseFloat(str);
if(num>5||num<0.1)
System.out.println("输入价格不在范围内,请重新输入!");
}
while(num>5||num<0.1);
System.out.println("您输入的数字是: "+num);
num=5-num;
if(num==0)System.out.println("不找钱!!");
else
{
System.out.println("应找钱为:");
num=num*100;
num_ge=(int)num%10;
num_shi=(int)num/10%10;
num_=(int)num/100;
if(num_!=0)
{
switch(num_)
{
case 1:System.out.print("一 元 1 张 ");break;
case 2:System.out.print("liang yuan 1 ge ");break;
case 3:System.out.print("yi yuan 1 ge liang yuan 1 ge ");break;
case 4:System.out.print("liang yuan 2 ge ");break;
}
}
if(num_shi!=0)
{
switch(num_shi)
{
case 1:System.out.print("一 角 1 个 ");break;
case 2:System.out.print("liang jiao 1 ge ");break;
case 3:System.out.print("yi jiao 1 ge liang jiao 1 ge ");break;
case 4:System.out.print("liang jiao 2 ge ");break;
case 5:System.out.print("whu jiao 1 ge ");break;
case 6:System.out.print("whu jiao 1 ge yi jiao 1 ge ");break;
case 7:System.out.print("whu jiao 1 ge liang jiao 1 ge ");break;
case 8:System.out.print("whu jiao 1 ge yi jiao 1 ge liang jiao 1 ge ");break;
case 9:System.out.print("whu jiao 1 ge liang jiao 2 ge ");break;
}
}
if(num_ge!=0)
{
switch(num_ge)
{
case 1:System.out.print("一 分 1 个 ");break;
case 2:System.out.print("liang fen 1 ge ");break;
case 3:System.out.print("yi fen 1 ge liang fen 1 ge ");break;
case 4:System.out.print("liang fen 2 ge ");break;
case 5:System.out.print("whu fen 1 ge ");break;
case 6:System.out.print("whu fen 1 ge yi fen 1 ge ");break;
case 7:System.out.print("whu fen 1 ge liang fen 1 ge ");break;
case 8:System.out.print("whu fen 1 ge yi fen 1 ge liang fen 1 ge ");break;
case 9:System.out.print("whu fen 1 ge liang fen 2 ge ");break;
}
}
}
}
}
我的qq150979313
热心网友
时间:2024-10-10 16:24
第二题有点小BUG,小数点后只有一位时总是会少0.01。比如输入0.1,0.2这样的值。
因为浮点数采用二进制表示,而二进制系统中无法精确表示1/10。要精确表示的话要用BigDecimal类。
第一题:
package net.pzw;
import java.util.Scanner;
public class MinAndMax {
public MinAndMax(int x,int y) {
int temp,a,b;
if(x<y){
temp=x;
x=y;
y=temp;
}
a=x;
b=y;
while(b!=0){
temp=a%b;
a=b;
b=temp;
}
System.out.println("两数最大公分子为:"+a);
System.out.println("两数最小公分母为:"+x*y/a);
}
public static void main(String[] args) {
int a,b;
Scanner scan=new Scanner(System.in);
System.out.print("请输入第一个数:");
a=scan.nextInt();
System.out.print("请输入第二个数:");
b=scan.nextInt();
new MinAndMax(a,b);
}
}
第二题:
package net.pzw;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Money {
private static final double FIVEYUAN=5.00;
private static final double TWOYUAN=2.00;
private static final double ONEYUAN=1.00;
private static final double FIFTHFENG=0.5;
private static final double TWENTYFENG=0.2;
private static final double TENFENG=0.1;
private static final double FIVEFENG=0.05;
private static final double TWOFENG=0.02;
private static final double ONEFENG=0.01;
public Money(double input) {
double money[]=new double[]{FIVEYUAN,TWOYUAN,ONEYUAN,FIFTHFENG,
TWENTYFENG,TENFENG,FIVEFENG,TWOFENG,ONEFENG};
double total=0,temp=money[0];
DecimalFormat myformat=new DecimalFormat("##.##");
for(int i=0;i<money.length;i++){
if(input>5||input<0.1){ System.out.println("请输入0.1-5间的数。");
break;
}
if(input==5){
System.out.println("刚好,不用找钱了。");
break;
}
if(temp-input>=money[i]){
do {
total=money[i];
System.out.println(total);
temp=temp-money[i];
temp=Double.parseDouble(myformat.format(temp));
} while (temp-input>money[i]);
}else{
continue;
}
}
}
static public void main(String[] args){
System.out.print("请输入一个数:");
Scanner scan=new Scanner(System.in);
double input=scan.nextDouble();
new Money(input);
}
}
热心网友
时间:2024-10-10 16:24
peizhengwen您好,谢谢您。您的程序其实已经很好了。我真的很谢谢您。我的qq:605489969,当然如果有时间能完善就更好了。-----happywebfish