阿,没认真看题目要求,要用循纤差激环语句来做,晕呀,那以下白写了庆判。
第二题
public boolean isSubString(String sub,String str){
sub = ".*" + sub + ".*"毁袜
if (str.matches(sub)) return ture;
else return false;
}
我用到了JAVA里的正则表达式,所以写起来就很短。
㈡ JAVA编程题!
//把你的那个表作成test3.txt放到D盘根,跑程序就好了
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class MyTest3 {
List stuInfoList = new ArrayList();
public MyTest3(){
printResult();
}
public void readFile() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\test3.txt")));
String line = "";
int i=0;
while ((line = br.readLine()) != null) {
if(i++>0){ //略过头上的汉字行
StudentInfo student = new StudentInfo(line.split(" "));
stuInfoList.add(student);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
class StudentInfo implements Comparable{
public int stuId;
public double pings;
public double qizhong;
public double qimo;
public double bishi;
public double zhongFeng;
public StudentInfo(){};
public StudentInfo(String[] info){
this.stuId = Integer.parseInt(info[0]);
this.pings = Integer.parseInt(info[1]);
this.qizhong = Integer.parseInt(info[2]);
this.qimo = Integer.parseInt(info[3]);
this.bishi = Integer.parseInt(info[4]);
this.zhongFeng = pings*0.1+qizhong*0.25+qimo*0.15+bishi*0.5;
}
public String getPingJunFeng(int size){
return pings/size +" "+qizhong/size+" "+qimo/size+" "+bishi/size+" "+zhongFeng/size;
}
public String toString(){
return stuId + " " +pings + " "+qizhong+" "+qimo+" "+bishi+" "+zhongFeng;
}
public int compareTo(Object arg0) {
StudentInfo info = (StudentInfo)arg0;
return (int)(info.zhongFeng-this.zhongFeng);
}
}
public void printResult(){
readFile();
System.out.println("学号 平时 期中 期末 笔试 总评分");
for(Iterator it=stuInfoList.iterator();it.hasNext();){
System.out.println(it.next());
}
System.out.println("-----------80分以上---------------\r\n学号 总评分");
for(Iterator it=stuInfoList.iterator();it.hasNext();){
StudentInfo info = (StudentInfo)it.next();
if(info.zhongFeng>=80)
System.out.println(info.stuId + " "+info.zhongFeng);
}
System.out.println("-----------没有及格---------------\r\n学号 总评分");
for(Iterator it=stuInfoList.iterator();it.hasNext();){
StudentInfo info = (StudentInfo)it.next();
if(info.zhongFeng<60)
System.out.println(info.stuId + " "+info.zhongFeng);
}
Collections.sort(stuInfoList);
System.out.println("-----------排序之后---------------\r\n学号 平时 期中 期末 笔试 总评分");
for(Iterator it=stuInfoList.iterator();it.hasNext();){
System.out.println(it.next());
}
StudentInfo pinjunfeng = new StudentInfo();
for(Iterator it=stuInfoList.iterator();it.hasNext();){
StudentInfo info = (StudentInfo)it.next();
pinjunfeng.bishi+=info.bishi;
pinjunfeng.pings+=info.pings;
pinjunfeng.qimo+=info.qimo;
pinjunfeng.qizhong+=info.qizhong;
pinjunfeng.zhongFeng+=info.zhongFeng;
}
System.out.println("-----------平均分---------------\r\n平时 期中 期末 笔试 总评分");
System.out.println(pinjunfeng.getPingJunFeng(stuInfoList.size()));
}
public static void main(String[] args) throws Exception {
new MyTest3();
}
}
㈢ JAVA编程题,随机产生数值在50以下的60个整数加入到数组列表中,求其中最大元素
import java.util.ArrayList;
import java.util.Collections;
public class Test {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<扰改Integer>();
for(int i=0;i<60;i++) {
list.add((int)(Math.random()*50));
}
System.out.println("最大元素值:"+Collections.max(list));
System.out.println(list);
System.out.println("频度出现2次及以上圆樱的数据:"橘李丛);
ArrayList<Integer>list2=new ArrayList<Integer>();
for(Integer i:list) {
if(Collections.frequency(list, i)>1) {
if(!list2.contains(i)) {
list2.add(i);
}
}
}
System.out.println(list2);
}
}
㈣ JAVA程序设计题(很简单的)
你的题有很多错误,我给你改了一下。
1.设变量i和j的定义如下,试分别计算下列表达式的值:
int i=1; double d=1.0;
1题 35/4 [8]
2题 46%9+4*4-2 [15]
3题 45+43%5*(23*3%2)[48]
4题 45+45*50%i-- [45]
5题 45+45*50%(i--) [45]
6题 1.5*3+(++d) [6.5]
7题 1.5*3+d++ [5.5]
8题 i+=3/i+3 [7]
程序阅读题
1给定如下代码,写出程序运行结果
class Example{
public static void main(String arges[]){
int i=0;
do{
System.out.println("doing it for i is:"+i);
}while(--i>0);
System.out.println("finish");
}
}
结果如下:
doing it for i is:0
finish
2 阅读程序段写出执行结果
for(int k=1;k<=5;k++){
if(k>4)break;
System.out.println("k="+k);
}
结果:
k=1
k=2
k=3
k=4
3试写出下列程序段循环的运行结果
int i=1;
while(i<10)
if(i++%2==0)
System.out.println(i);
结果:
3
5
7
9
操作题
求1!+2!+...+10!
public static void main(String arges[]){
long sum = 0;
for(int i = 1; i <= 10; i++) {
long s = 1;
for(int j = 1; j <= i; j++) {
s *= j;
}
sum += s;
}
System.out.println("sum = " + sum);
}
求100之内的所有“完数”。完数是指等于它的因子和的数。例如:6=1+2+3,6=1*2*3,则6是一个完数
public class wanshu{
public static void main(String[] args) {
for(int i = 1; i <= 100; i++) {
if(fun(i)) {
System.out.println(i);
}
}
}
public static boolean fun(int num) {
int sum = 0;
for(int i = 1; i < num; i++) {
if(num % i == 0) {
sum += i;
}
}
return num == sum;
}
}
㈤ JAVA编程题目,求大神解答。
importjava.util.Scanner;
publicclassTest{
publicstaticvoidmain(String[]args){
int[]bills={100,50,20,10,5,2,1};
int[]numBills=newint[bills.length];
Scannersc=newScanner(System.in);
intamount=sc.nextInt();
inti=0;
do{
intbill=bills[i];
numBills[i++]=amount/bill;
amount%=bill;
}while(amount>0&&i<bills.length);
for(i=0;i<bills.length;i++)
System.out.println(bills[i]+"元:"+numBills[i]+"张");
}
}
4582
100元:45张
50元:1张
20元:1张
10元:1张
5元:0张
2元:1张
1元:0张
98888
100元:988张
50元:1张
20元:1张
10元:1张
5元:1张
2元:1张
1元:1张
适合整数金额,角分小数的还要稍加修改..
㈥ 100分,几道简单的Java编程题,帮忙解决一下!
不是我牛叉
以前有过类似的练习
修改了一陪册乎下就姿裤发了
我也同意楼下的观点 自己动手做一下
有什么不明白的可以参考我的这个
也许你有更好的解决方法
1.
import java.util.Scanner;
public class Test_If_Switch
{
public static void main(String[] args) {
System.out.println("输入一个数字:");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println("方法1:"+methodl(x));
System.out.println("方法2:"+method2(x));
}
static int methodl(int x)
{
int result = 0;
if(x<0)
result = 2*x-1;
else if(x>=0&&x<3)
result = 3*x+5;
else if(x>=3&&x<5)
result = x+1;
else if(x>=5&&x<10)
result=5*x-3;
else if(x>=10)
result = 7*x+2;
return result;
}
static int method2(int x)
{
int result = 0;
switch(x)
{
case 0:
case 1:
case 2:result = 3*x+5;break;
case 3:
case 4:result = x+1;break;
case 5:
case 6:
case 7:
case 8:
case 9:result=5*x-3;break;
case 10:result = 7*x+2;break;
default:result = 2*x-1;break;
}
return result;
}
}
2.
import java.util.Scanner;
public class Test_Tn {
public static void main(String[] args) {
System.out.println("输入一个数字:");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println("第"+x+"项的值为:"+method(x));
}
static long static method(int n) {
long Tn = 0;
if (x == 1)
Tn = 1;
else
Tn = method(x - 1) + x;
return Tn;
}
}
3.
public class test
{
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++;
}
}
}
4.
public class Money {
public static void main(String[] args)
{
int a = 100,b = 50, c =10;
for(int i =5;i<=8;i++)
for(int j = 0;j<=6;j++)
for(int k = 0;k<30;k++)
{
if(a*i+b*j+c*k==800)
System.out.println("芦悉100元"+i+"张"+"50元"+j+"张"+"10元"+k+"张");
}
}
}
㈦ 简单java编程题,运行成功追加20
1)用equals()方法判断,Test t=new Test(2,4); Test t1=new Test(2,4);是否相等。不相等
public class Test {
private int a;
private int b;
public Test(int a, int b){
this.a = a;
this.b = b;
}
public static void main(String[] args) {
Test t=new Test(2,4);
Test t1=new Test(2,4);
boolean isEqual = t.equals(t1);
System.out.println(isEqual);
}
}
2)设计一种手段,让t.equals(t1)相等.,结果相等。
public class Test {
private int a;
private int b;
public Test(int a, int b){
this.a = a;
this.b = b;
}
public static void main(String[] args) {
Test t=new Test(2,4);
Test t1=new Test(2,4);
boolean isEqual = t.equals(t1);
System.out.println(isEqual);
}
public boolean equals(Object o) {
if(o instanceof Test){
Test t2 = (Test) o;
return t2.a == this.a && t2.b == this.b;
}
return false;
}
}
总结:如果子类不重写Object.equals()方法,那么两个对象比较的是内存地凳租址;如果子类重写equals()方法,里面可以根据自己的需要来定义,从而避免比枣晌兆较内存地址谨饥。。
㈧ java编程题 希望大家能够帮助我一下,谢谢
package book;
/**
* @Author: Cool_Wu
* @Date: 2020-12-07 20:18
*/
public class Book {
private String name;
private String num;
private String author;
private double price;
private String publishing_House;
private String publication_Date;
public Book() {}
public Book(String name, String num, String author, double price, String publishing_House, String publication_Date) {
this.name = name;
this.num = num;
this.author = author;
this.price = price;
this.publishing_House = publishing_House;
this.publication_Date = publication_Date;
}
@Override
public String toString() {
return "图书信息: ----------------------" +
" 书名:" + name +
" 书号:" + num +
" 作者:" + author +
" 单价:" + price +
" 出版社:" + publishing_House +
" 出版日期:" + publication_Date +
" ---------------------- ";
}
}
package book;
public class Test {
public static void main(String[] args) {
Book book1 = new Book("百年孤独","10000","加西亚·马尔克斯",40.00,"南海出版公司","2017年08月");
System.out.println(book1);
Book book2 = new Book("时间简史","10086","史蒂芬·霍金",22.50,"湖南科技出版社","2014年06月");
System.out.println(book2);
}
}
运行结果
㈨ 5道简单的JAVA编程题(高分悬赏)
很详细的帮你写下,呵呵,所以要给分哦!
1、
(1)源程序如下:
public class One {
public static void main(String[] args) {
String name = "张三";
int age = 23;
char sex = '男';
String myclass = "某某专业2班";
System.out.println("姓名:" + name);
System.out.println("姓名:" + age);
System.out.println("姓名:" + sex);
System.out.println("姓名:" + myclass);
}
}
(2)
编写完程序的后缀名是.java,如本题,文件名就是One.java。
开始\运行\cmd,进入“命令提示符窗口”,然后用javac编译器编译.java文件,语句:javac One.java。
(3)
编译成功后,生成的文件名后缀是.class,叫做字节码文件。再用java解释器来运行改程序,语句:java One
2、编写程序,输出1到100间的所有偶数
(1)for语句
public class Two1 {
public static void main(String[] args) {
for(int i=2;i<=100;i+=2)
System.out.println(i);
}
}
(2)while语句
public class Two2 {
public static void main(String[] args) {
int i = 2;
while (i <= 100) {
System.out.println(i);
i += 2;
}
}
}
(3)do…while语句
public class Two3 {
public static void main(String[] args) {
int i = 2;
do {
System.out.println(i);
i += 2;
}while(i<=100);
}
}
3、编写程序,从10个数当中找出最大值。
(1)for循环
import java.util.*;
public class Three1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
for (int i = 0; i < 10; i++) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
}
System.out.println("最大值:" + max);
}
}
(2)while语句
import java.util.*;
public class Three2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
while (i < 10) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
i++;
}
System.out.println("最大值:" + max);
}
}
(3)do…while语句
import java.util.*;
public class Three3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
do {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
i++;
}while(i<10);
System.out.println("最大值:" + max);
}
}
4、编写程序,计算从1到100之间的奇数之和。
(1)for循环
public class Four1 {
public static void main(String[] args) {
int sum=0;
for(int i = 1;i<=100;i+=2){
sum+=i;
}
System.out.println("1~100间奇数和:" + sum);
}
}
(2)while语句
public class Four2 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i <= 100) {
sum += i;
i += 2;
}
System.out.println("1~100间奇数和:" + sum);
}
}
(3)do…while语句
public class Four3 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
do {
sum += i;
i += 2;
} while (i <= 100);
System.out.println("1~100间奇数和:" + sum);
}
}
5、
(1)什么是类的继承?什么是父类?什么是子类?举例说明。
继承:是面向对象软件技术当中的一个概念。如果一个类A继承自另一个类B,就把这个A称为"B的子类",而把B称为"A的父类"。继承可以使得子类具有父类的各种属性和方法,而不需要再次编写相同的代码。在令子类继承父类的同时,可以重新定义某些属性,并重写某些方法,即覆盖父类的原有属性和方法,使其获得与父类不同的功能。另外,为子类追加新的属性和方法也是常见的做法。继承需要关键字extends。举例:
class A{}
class B extends A{}
//成员我就不写了,本例中,A是父类,B是子类。
(2)编写一个继承的程序。
class Person {
public String name;
public int age;
public char sex;
public Person(String n, int a, char s) {
name = n;
age = a;
sex = s;
}
public void output1() {
System.out.println("姓名:" + name + "\n年龄:" + age + "\n性别:" + sex);
}
}
class StudentPerson extends Person {
String school, department, subject, myclass;
public StudentPerson(String sc, String d, String su, String m, String n,
int a, char s) {
super(n, a, s);
school = sc;
department = d;
subject = su;
myclass = m;
}
public void output2() {
super.output1();
System.out.println("学校:" + school + "\n系别:" + department + "\n专业:"
+ subject + "\n班级:" + myclass);
}
}
public class Five2 {
public static void main(String[] args) {
StudentPerson StudentPersonDemo = new StudentPerson("某某大学", "某某系别",
" 某专业", "某某班级", " 张三", 23, '男');
StudentPersonDemo.output2();
}
}