189 8069 5689

java练习题代码 java 代码题

java练习题求大神刚学

按照题目要求编写的商品类Item的Java程序如下

创新互联专业为企业提供古交网站建设、古交做网站、古交网站设计、古交网站制作等企业网站建设、网页设计与制作、古交企业网站模板建站服务,10年古交做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

public class Item{

public String code,name,type;

public double price;

public static int totalNum=0;

public Item(){}

public Item(String code,String name){

this.code=code;

this.name=name;

totalNum++;

}

public static void main(String[] args){

Item[] item=new Item[10];

item[0]=new Item("666","戴尔(DELL) 游戏笔记本");

item[0].type="游戏";item[0].price=5499.00;

item[1]=new Item("007","苹果(Macbook pro)笔记本");

item[1].type="电脑,办公";item[1].price=18000.00;

for(int i=0;iItem.totalNum;i++){

System.out.println("名称:"+item[i].name+",价格:"+item[i].price);

}

System.out.println("总商品数量:"+Item.totalNum);

}

}

求助java代码 这个练习题怎么写

import java.util.Scanner;

public class Text {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("登陆菜单");

Scanner sc, sz;

int x;

while (true) {

sc = new Scanner(System.in);

System.out.println("输入序号选择功能");

System.out.println("1.登录系统");

System.out.println("2.退出");

x = sc.nextInt();

switch (x) {

case 1:

boolean p = true;

while (p) {

int y;

sz = new Scanner(System.in);

System.out.println("输入序号选择功能");

System.out.println("1.客户信息管理");

System.out.println("2.购物结算");

System.out.println("3.真情回馈");

System.out.println("4.注销");

y = sz.nextInt();

switch (y) {

case 1:

System.out.println("欢迎进入《客户信息管理》");

break;

case 2:

System.out.println("欢迎进入《购物结算》");

break;

case 3:

System.out.println("欢迎进入《真情回馈》");

break;

case 4:

p = false;

System.out.println("注销成功!");

break;

default:

System.out.println("输入错误");

break;

}

}

break;

case 2:

System.out.println("谢谢您的使用!");

return;

default:

System.out.println("输入错误!");

break;

}

}

}

}

帮忙写个java的练习题代码,万分感谢!!!

public class myTest

{

public static void main(String[] args)

{

String[] strArr = { "010", "3223", "666", "7890987", "123123" };

System.out.println(getSymmetricString(strArr));

}

public static String getSymmetricString(String[] strArr)

{

String allInfo = "";

int sum = 0;

for (String str : strArr)

{

boolean flag = true;

for (int i = 0; i  str.length() / 2; i++)

{

String bgnStr = str.substring(i, i + 1);

String endStr = str.substring(str.length() - (i + 1), str.length() - i);

if (!bgnStr.equals(endStr))

{

flag = false;

break;

}

}

if (flag)

{

allInfo = allInfo + str + "是对称的,对称的数量为:" + str.length() / 2 + "\n";

sum++;

}

else

{

allInfo = allInfo + str + "不是对称的" + "\n";

}

}

return allInfo + "\n对称字符的个数为:" + sum;

}

}

JAVA 练习题

public class JavaExos {

public static void charInt(String chaine){ //1044

String[] charInt = new String[2];

int count = -1;

char maxChar = 'A';

int[] letterCount = new int[26];

String word = chaine.toLowerCase();

for (int i=0;iword.length();i++) {

int indexOfChar = (byte)word.charAt(i)-97;

letterCount[indexOfChar]++;

if (letterCount[indexOfChar]count || (letterCount[indexOfChar]==count word.charAt(i)maxChar)){

count = letterCount[indexOfChar];

maxChar = word.charAt(i);

}

}

charInt[0] = String.valueOf(maxChar);

charInt[1] = ""+count;

System.out.println(charInt[0]+" "+charInt[1]);

}

public static void getDate(int n){ //1047 这题如果给1,其实是指2000年1月2号.

n++;

int[] getYear = getYear(n);

int year = getYear[0];

int[] getMonth = getMonth(year,getYear[1]);

int month = getMonth[0];

String monthString ;

if(month10) monthString = "0"+String.valueOf(month);

else monthString = String.valueOf(month);

int day = getMonth[1];

System.out.println(year+"-"+monthString+"-"+day+" "+getDayOfWeek(n));

}

private static boolean isBissextile(int n){

if (n%4==0 !(n%100==0n%400!=0))

return true;

else

return false;

}

private static int[] getYear(int n){

int[] getYear = new int[2];

int year = 2000;

while(n0){

if(isBissextile(year)) n -= 366;

else n -= 365;

if (n0) year++;

}

if(isBissextile(year)) n+=366;

else n += 365;

getYear[0] = year;

getYear[1] = n;

return getYear;

}

private static int[] getMonth(int year, int n){

int[] getMonth = new int[2];

int month = 1;

while(n0){

if(month=7 month%2 != 0) n -= 31;

else if (month==2 isBissextile(year) ) n -= 29;

else if (month==2 !isBissextile(year)) n -= 28;

else if(month=7 month%2==0) n -= 30;

else if(month%2==0) n-=31;

else n -= 30;

if (n0) month++;

}

if(month=7 month%2 != 0) n += 31;

else if (isBissextile(year) month==2) n += 29;

else if (!isBissextile(year) month==2) n += 28;

else if(month=7 month%2==0) n += 30;

else if(month%2==0) n+=31;

else n += 30;

getMonth[0] = month;

getMonth[1] = n;

return getMonth;

}

private static String getDayOfWeek(int n){

int quotient = n/7;

int remainder = n -= quotient*7;

switch(remainder){

case 0 : return "Sunday";

case 1 : return "Monday";

case 2 : return "Tuesday";

case 3 : return "Wednesday";

case 4 : return "Thursday";

case 5 : return "Friday";

case 6 : return "Saturday";

default : return "Never arrive";

}

}

public static void getCode(String chaine){ //1048

chaine = chaine.toUpperCase();

System.out.println("START");

System.out.println(chaine);

System.out.println("END");

System.out.println();

for(int i=0;ichaine.length();i++){

System.out.print((changChar(chaine.charAt(i))));

}

System.out.println();

}

private static char changChar(char c){

if(c=65 c=90 c-565) return (char)(c+26-5);

else if(c=65 c=90) return (char)(c-5);

else return c;

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

JavaExos.charInt("adfadffasdfda");

JavaExos.getDate(1751);

JavaExos.getCode("NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX");

java练习题求完整代码

按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下

需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果

Student.java文件代码如下

package user.java.test;

import java.io.Serializable;

public class Student implements Serializable{

private static final long serialVersionUID = 1L;

private String no;

private String name;

private double score;

public Student(){}

public Student(String no,String name,double score){

this.no=no;

this.name=name;

this.score=score;

}

public String getNo(){ return no;}

public void setNo(String no){ this.no=no;}

public String getName(){ return name;}

public void setName(String name){ this.name=name;}

public double getScore(){ return score;}

public void setScore(double score){ this.score=score;}

public String toString(){

return "学号:"+no+",姓名:"+name+",成绩:"+score;

}

public static double getAvg(Student[] sArray){

double sum=0,avg;

for(int i=0;isArray.length;i++){

sum=sum+sArray[i].getScore();

}

avg=sum/sArray.length;

return avg;

}

}

Test.java文件代码如下

package user.java.test;

public class Test{

public static void main(String[] args){

Student[] sArray=new Student[5];

sArray[0]=new Student("001","张三",89.5);

sArray[1]=new Student("002","李四",82.5);

sArray[2]=new Student("003","王五",93);

sArray[3]=new Student("004","赵六",73.5);

sArray[4]=new Student("005","孙七",66);

System.out.println("这些学生的平均分:"+Student.getAvg(sArray));

for(int i=0;isArray.length;i++){

System.out.println(sArray[i].toString());

}

}

}

Java 练习题 1!+2!+...+n!=? 代码如下帮忙看看哪里不对呢?当n=3的时候就不对了

把long multiplyj=1;移到for-i循环内,for-j循环外,每个数的阶乘前都要初始化一下multiplyj变量.就对了

完整的Java程序如下

import java.util.Scanner;

public class Practice{

public static void main(String[]args){

Scanner in =new Scanner(System.in);

System.out.print("请输入num的值");

int num=in.nextInt();  

long multiplyi=0;

for(int i=1;i=num;i++){

long multiplyj=1;//这里把这句移到这里

for(int j=1;j=i;j++){

multiplyj *=j;

}

multiplyi +=multiplyj;

}

System.out.println(multiplyi);

}

}

运行结果

请输入num的值3

9


当前文章:java练习题代码 java 代码题
网址分享:http://cdxtjz.cn/article/hjhchc.html

其他资讯