当前位置:首页 » 编程语言 » java编程题

java编程题

发布时间: 2022-01-08 06:41:22

java编程题目

重点是根据a的值,生成各个数,先根据数字重复长度生成对应的字符串,再利用循环进行相加,相加时把字符串转换成数字即可。

㈡ Java编程题

先把题目列成公式就是2*a+3*b+4*c+5*d=20

这就是一个四元一次方程
简单点就四次循环就可以得到答案
public static void main(String[] args) {

int min=0;//不可能买负数
for (int a =min; a <=20/2; a++) {
for (int b =min; b <20/3; b++) {
for (int c = min; c <20/4; c++) {
for (int d = min; d <20/5; d++) {
if(2*a+3*b+4*c+5*d==20){
System.out.println("菊花"+a);
System.out.println("康乃馨"+b);
System.out.println("玫瑰"+c);
System.out.println("百合"+d);
}
}

}
}
}

}

㈢ java题目编程题

首先初始化一个HashMap,存入一些用户名和电话号码的初始值,然后分别使用map的API来进行相应的map增删改查操作就行了。

增/改:put(K key,V value),这里可以初始化用户名为key,电话号码为value,前提是用户名要没有重复的,如果是相同的用户名会覆盖前一个,可以当做改功能来使用
删:remove(Object key)根据键,删值,如果之前的key存的用户名,那么这里就是根据用户名删值
查:get(Object key)根据键查值,相当于根据用户名查电话号码

㈣ java编程题

使用Random类和for循环输出0~100内的随机整数


importjava.util.Random;
publicclassRandomPrint{
publicstaticvoidmain(String[]args){
Randomr=newRandom();//不传入种子
for(inti=0;i<8;i++){
System.out.println(r.nextInt(100));
}

}
}

㈤ java编程十道题

1.
public class TestRandomArray
{
public static void main(String[] args)
{
int maxline = (int) (Math.random()*100);
int[] array = new int[maxline];
for(int i=0;i<maxline;i++)
{
int temp = (int) (Math.random()*100);
if(temp>=10&&temp<=99)
{
array[i] = temp;
}
else
i--;
}
for(int j=0;j<maxline;j++)
{
int max = array[0];

if(array[j]>max)
{
max=array[j];
array[j] = array[0];
array[0] = max;

}
}
for(int k=0;k<maxline;k++)
{
System.out.print(array[k]+" ");
}
}
}

2.
public class TestNumber100
{
public static void main(String[] args)
{
for(int i=1;i<100;i++)
{
if(i%3==0&&(i%5!=0)&&(i%9!=0))
System.out.println(i+" ");
else
continue;
}
}
}

3.貌似没结果
public class Test3
{
public static void main(String[] args)
{
/*for(int i=0;i<=9;i++)
{
for(int j=0;j<=9;j++)
{
int code = 10000+i*1000+j*100+23;
if((code%57)==0&&(code%67)==0&&i!=j)
{
System.out.println("x="+i+","+"y="+j);
}
else
System.out.println(i+" "+j);
}
}*/

for(int i=10023;i<=19923;i++)
if(i==0&&i==0)
System.out.println(i+" ");
}
}

4.
class Caculate {
int money;
Caculate(){
money = 10;
}
public int charge (int distance){
if (distance < 3){
money = 10;
}
if ((distance >= 3) && distance < 15)
{
money = money + 2*(distance-3);
}
if (distance > 15 )
{
money = money + 2*12 + 3*(distance - 15);
}

return money;
}
public static void main(String args[]) {

System.out.println("请输入公里数");
int distance_example=0;
Scanner key = new Scanner(System.in);
int n = key.nextInt();
distance_example = n;
Caculate pay = new Caculate();
pay.money = pay.charge(distance_example);
System.out.println("You need to pay money:"+pay.money+" distance is:"+distance_example);

}
}

5.
public class Test4
{

public static void main (String args[])
{
int n=100;
while(n<=1000)
{
int i,j,k;
i=n/100;
j=(n-i*100)/10;
k=n%10;
if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n)

System.out.print(n+String.valueOf('\t'));
n++;
}
}
}

6.
public class TestMoney
{
public static void main(String[] args)
{
int one=1,two=2,five=5;
for(int i=1;i<100;i++)
for(int j=1;j<50;j++)
for(int k=1;k<20;k++)
{
if((i*one+j*two+k*five)==100)
System.out.println(i+"个一分,"+j+"个两分,"+k+"个五分");
}

}

}

7.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestJieCheng
{
public static void main (String args[])
{
int a=0,b=1;float sum=0;
System.out.print("请输入要计算的阶乘:");
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
a=Integer.parseInt(in.readLine());
}catch(IOException e){}
for(int i=1;i<=a;i++)
{
b=b*i;

}
System.out.print(a+"的阶乘是"+b);
}
}

8.
public class Test4
{

public static void main (String args[])
{
int n=100;
while(n<=1000)
{
int i,j,k;
i=n/100;
j=(n-i*100)/10;
k=n%10;
if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n)

System.out.print(n+String.valueOf('\t'));
n++;
}
}
}

9.
public class TestNumber2
{
public static void main(String[] args)
{
final int maxline = 20;
double sum = 0;
double [] denominator = new double [maxline];
double [] numerator = new double [maxline];
for(int i=2;i<denominator.length;i++)
{
denominator[0]=1;
denominator[1]=2;
denominator[i]=denominator[i-1]+denominator[i-2];
}
for(int j=2;j<numerator.length;j++)
{
numerator[0]=2;
numerator[1]=3;
numerator[j]=numerator[j-1]+numerator[j-2];
}
for(int k=0;k<maxline;k++)
{
sum+=(numerator[k])/denominator[k];

}
System.out.println(sum);
}

}

10.
import java.io.*;

public class 根据输入的三个数求一元二次方程
{
public static void main (String args[]) throws NumberFormatException, IOException
{
float a[]=new float [3];
for(int i=0;i<a.length;i++)
{
System.out.println("请输入第"+(i+1)+"个数");
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
a[i]=Float.parseFloat(in.readLine());
}
float x1=0,x2=0;
x1=(float) ((((-1)*a[1])+(Math.sqrt(a[1]*a[1]-4*a[0]*a[2])))/(2*a[0]));
x2=(float) ((((-1)*a[1])-(Math.sqrt(a[1]*a[1]-4*a[0]*a[2])))/(2*a[0]));
System.out.print(a[0]+"X2"+a[1]+"X"+a[2]+"的两个根是:");
System.out.print(x1+"和"+x2);
}
}

㈥ JAVA编程题

publicclassTest{
publicstaticvoidmain(String[]args){
int[]arr={12,22};//指定数组
intresutl=getSum(arr);//求十位数为奇数的数值的和
System.out.println(resutl);
}

publicstaticintgetSum(int[]arr){
intresult=0;//结果
for(inti=0;i<arr.length;i++){//注意这里的循环次数是arr的长度,而不是100
intnum=arr[i];//从数组里取出这个数字
if(num>9&&num<100){//题目要求数字是1~100之间的数,且有十位,那么说明数值范围是[10,99]
if((num/10)%2!=0){//如果十位是奇数.
result+=num;//那么累加到结果里
}
}
}
returnresult;//返回结果
}
}

㈦ java编程题

importjava.util.Arrays;
importjava.util.Scanner;
publicclassTestExample{
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner(System.in);
intn=Integer.parseInt(scanner.nextLine());
int[][]index=newint[n][2];//数组存储相关信息
for(inti=0;i<n;i++){
String[]a=scanner.nextLine().split("\s");
intx=Integer.parseInt(scanner.nextLine());
index[i][0]=x;
index[i][1]=-1;
for(intj=0;j<6;j++){
if(String.valueOf(x).equals(a[j])){
index[i][1]=j;
break;
}
}
}
//数组信息输出
for(inti=0;i<n;i++){
if(index[i][1]!=-1){
System.out.println(index[i][0]+":"+"a["+index[i][1]+"]");
}else
System.out.println(index[i][0]+":"+"notfound");
}
scanner.close();
}
}

㈧ Java编程题

package joshua.fraction.test;
public class Fraction extends Object {
private int numerator;
private int denominator;
public int getNumerator() {
return numerator;
}
public int getDenominator() {
return denominator;
}
public Fraction(int numerator, int denominator) {
this.numerator = numerator;
this.denominator = denominator;
}
public String addition(Fraction fraction){
int numerator;
int denominator;
int greatestCommonDivisor;
StringBuilder result = new StringBuilder();
result.append("(");
if(this.denominator==fraction.getDenominator()){
numerator = this.numerator + fraction.getNumerator();
denominator = this.denominator;
}else{
numerator = this.numerator*fraction.getDenominator()+fraction.getNumerator()*this.denominator;
denominator = this.denominator*fraction.getDenominator();
}
greatestCommonDivisor = getGreatestCommonDivisor(numerator, denominator);
return result.append(numerator/greatestCommonDivisor).append(")/(").append(denominator/greatestCommonDivisor).append(")").toString();
}
public String subtraction(Fraction fraction){
int numerator;
int denominator;
int greatestCommonDivisor;
StringBuilder result = new StringBuilder();
result.append("(");
if(this.denominator==fraction.getDenominator()){
numerator = this.numerator - fraction.getNumerator();
denominator = this.denominator;
}else{
numerator = this.numerator*fraction.getDenominator()-fraction.getNumerator()*this.denominator;
denominator = this.denominator*fraction.getDenominator();
}
greatestCommonDivisor = getGreatestCommonDivisor(numerator, denominator);
return result.append(numerator/greatestCommonDivisor).append(")/(").append(denominator/greatestCommonDivisor).append(")").toString();
}
@Override
public String toString() {
return "(" + numerator + ")/( " + denominator + ")";
}
@SuppressWarnings("unused")
private int getLeastCommonMultiple(int a, int b){
int sum = a*b;
return sum/getGreatestCommonDivisor(a, b);
}
private int getGreatestCommonDivisor(int a, int b){
int r;
for (;;) {
r = a % b;
a = b;
b = r;
if (r == 0) {
break;
}
}
return a;
}
}

package joshua.fraction.test;
public class Test {
public static void main(String[] args) {
Fraction a = new Fraction(1, 3);
Fraction b = new Fraction(1, 2);
System.out.println("" + a + "+" + b + "=" + a.addition(b));
System.out.println("" + a + "-" + b + "=" + a.subtraction(b));
}
}

第二题:

package joshua.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class test {
public static void main(String[] arg) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please input a Integer:");
StringBuffer sb = new StringBuffer();
Iterator<Integer> it = null;
try {
String input = reader.readLine();
it = find(Integer.valueOf((input == null || input.length() == 0) ? "0" : input)).iterator();
while (it != null && it.hasNext()) {
sb.append(it.next()).append(",");
}
if(sb.toString().length()>0)
System.out.println("result is: "+ sb.toString().substring(0, sb.toString().length() - 1));
reader.readLine();
} catch (Exception e) {
e.printStackTrace();
}
}
public static List<Integer> find(int arg){
List<Integer> list = new ArrayList<Integer>();
for(int i=1; i<arg; i++){
if(i%7==0){
list.add(i);
}else{
String str = String.valueOf(i);
char[] cs = str.toCharArray();
for(int j=0; j<cs.length; j++){
if("7".equals(String.valueOf(cs[j]))){
list.add(i);
break;
}
}
}
}
return list;
}
}

㈨ Java-编程题

public class Main {

public static int reverseInt(int input) {
int reversedNum = 0;
while (input != 0) {
reversedNum = reversedNum * 10 + input % 10;
input = input / 10;
}
return reversedNum;
}

public static void main(String[] args) {
int input = 352;
int reversed = reverseInt(input);
System.out.println("Reversed=" + String.valueOf(reversed));
}
}

热点内容
安卓手机玩mc卡怎么办 发布:2024-12-23 12:15:46 浏览:5
mt编译时出现错误信息 发布:2024-12-23 12:15:45 浏览:107
双存储冗余 发布:2024-12-23 12:09:16 浏览:664
解压缩太慢 发布:2024-12-23 12:08:36 浏览:535
linux恢复误删文件 发布:2024-12-23 11:59:36 浏览:493
平板电脑账号登录服务器错误 发布:2024-12-23 11:41:07 浏览:99
金蝶kis专业版数据库表 发布:2024-12-23 11:35:41 浏览:602
相册已经加密如何改密码 发布:2024-12-23 11:32:20 浏览:277
批量下载链接脚本 发布:2024-12-23 11:29:11 浏览:973
PHP画a梦 发布:2024-12-23 11:28:01 浏览:199