91嫩草国产线免费观看_欧美日韩中文字幕在线观看_精品精品国产高清a毛片_六月婷婷网 - 一级一级特黄女人精品毛片

一道JAVA編程題 求大神指教啊!急求!

首頁 > 知識(shí)產(chǎn)權(quán)2021-12-04 11:54:07

有一道JAVA 題不會(huì),求大神指教該怎么做啊 ,急求!!

(模式識(shí)別方面,四個(gè)連續(xù)相等的數(shù))編寫下面的方法,測(cè)試某個(gè)數(shù)組中是否有四個(gè)連續(xù)的值相同的數(shù)字rn publicBoolean isConsecutiveFour(int[] values)rn編寫測(cè)試程序,提示用戶輸入一個(gè)整數(shù)數(shù)列,如果這個(gè)數(shù)列有四個(gè)連續(xù)的具有相同值的數(shù),那就顯示true,否則顯示false。
代碼如下……
參數(shù)跟返回值你可以自己添加咯!
Scanner qvod = new Scanner(System.in);
String s = qvod.next();
char[] c = new char[s.length()];
boolean b = false;

for (int i = 0; i < c.length; i++) {
c[i]=s.charAt(i);
}

for (int i = 0; i < c.length; i++) {
//防止數(shù)組越界操作
if (c.length>i+3) {
if (c[i]==c[i+1]&&c[i]==c[i+2]&&c[i]==c[i+3]) {
b=true;
}
}
}

if (b) {
System.out.println("TRUE");
} else {
System.out.println("FALSE");
}
-------------------------------------分割完結(jié)線--------------------------
public static void main(String[] args) {
isConsecutiveFour(new int[]{5,2,3,5});//用戶輸入的數(shù)
}

public static Boolean isConsecutiveFour(int[] values){

int[] n=new int[]{5,2,3,5};///指定的數(shù)

if(n.length==values.length){

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

if(n[i]!=values[i]){
System.out.println("false");
return false;
}

}
System.out.println("true");
return true;

}

return null;

}

最粗暴的做法..用for循環(huán)

public boolean isConsecutiveFour(int[] values){
 boolean flag = false ;
 int i=0 ;
 int len = values.length ;
 while(!flag&&i<len-1){
 if(values[i]==values[i+1]){
 if((i+2<len)&&values[i+1]==values[i+2]){
 if((i+3<len)&&values[i+2]==values[i+3]){
 flag = true ;
 }
 }
 }
 i++ ;
 }
 return flag ;
}

一道java編程題,看不懂什么意思,求指教!

用Java類表示平面解析幾何上的基本圖形線段(Line)和矩形(Rectangle),并且這兩個(gè)類都是類Shape的子類。類Shape聲明如下:rnrnpublic class Shape {rnprivate String name;rnrnpublic Shape(){rn}rnpublic Shape(String name){rnthis.name = name;rn}rn}
就是叫你定義2個(gè)類 一個(gè)為基本圖形線段(Line) ,一個(gè)為矩形(Rectangle)。這2個(gè)類都要繼承Shape類
public class Line extends Shape{
public Line (String name){
super(name);
}
}

public class Rectangleextends Shape{
public Rectangle(String name){
super(name);
}
}
這個(gè)java類的構(gòu)造器,第一個(gè)是無參構(gòu)造器,不寫的話會(huì)默認(rèn)一個(gè)無參構(gòu)造器,第二個(gè)是帶一個(gè)參數(shù)的構(gòu)造器。構(gòu)造器是用來創(chuàng)建java類的時(shí)候調(diào)用的
類Shape 是一個(gè)帶參數(shù)的構(gòu)造方法和一個(gè)不帶參數(shù)的構(gòu)造方法,基本圖形線段(Line)和矩形(Rectangle)這兩個(gè)繼承它,肯定是用到了類Shape里面不同的方法唄
這個(gè)Shape類是一個(gè)父類,里面定義了一個(gè)類屬性,和兩個(gè)構(gòu)造函數(shù)。Line和Rectangle繼承Shape這個(gè)父類
我也不知道
我也看不懂你的意思

求一道Java編程題!!!

求一道Java編程題!!!編寫一個(gè)抽象類Person,內(nèi)有變量姓名name,年齡age,性別sex,有構(gòu)造方法。定義一個(gè)接口Jiekou,接口中有常量國籍country和顯示成員變量的printinfo()方法。定義Person類的子類Student,增加變量學(xué)校school、專業(yè)zhuanye;定義Person類的子類Teacher,增加變量學(xué)校school、職稱zhicheng、主講課程teach。類Student和Teacher都使用了該接口。寫出一個(gè)主類,測(cè)試上述類的正確性,測(cè)試時(shí)使用上轉(zhuǎn)型對(duì)象和接口回調(diào)技術(shù)來體現(xiàn)多態(tài)性
--接口
public interface DisplayPeople {
public final String country="China";
void printInfo(Person p);
}
--抽線類
public abstract class Person implements DisplayPeople{
private String name;
private int age;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}

public Person(){}
public Person(String name, int age, String sex) {
this();
this.name = name;
this.age = age;
this.sex = sex;
}

}
--Student類
public class Student extends Person implements DisplayPeople{
private String school;
private String profession;
public Student(String school, String profession) {
super();
this.school = school;
this.profession = profession;
}
public Student() {

}
@Override
public void printInfo(Person p) {
// TODO Auto-generated method stub
System.out.println("country:"+DisplayPeople.country+";name:"+p.getName()+";age:"+p.getAge()+";sex:"+p.getSex()+";school:"+this.getSchool()+";profession:"+this.getProfession());
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}

}

--Teacher類
public class Teacher extends Person implements DisplayPeople{
private String school;
private String zhicheng;
private String teach;
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public String getZhicheng() {
return zhicheng;
}
public void setZhicheng(String zhicheng) {
this.zhicheng = zhicheng;
}
public String getTeach() {
return teach;
}
public void setTeach(String teach) {
this.teach = teach;
}
@Override
public void printInfo(Person p) {
System.out.println("country:"+DisplayPeople.country+";name:"+p.getName()+";age:"+p.getAge()+";sex:"+p.getSex()+";school:"+this.getSchool()+";zhicheng:"+this.getZhicheng()+";teach:"+this.getTeach());

}

}
--測(cè)試類
public class Client {

public static void main(String[] args) {
Student student=new Student();
student.setAge(20);
student.setName("John");
student.setSex("Male");
student.setProfession("couputer");
student.setSchool("Beijingdaxue");
Person p=student;
p.printInfo(p);

Teacher tea=new Teacher();
tea.setAge(25);
tea.setName("Mary");
tea.setSex("Female");
tea.setTeach("English");
tea.setSchool("Beijingdaxue");
Person p1=tea;
p.printInfo(p1);
}

}
public class Test {// 測(cè)試類
public static void main(String[] args) throws IOException {

Student s = new Student("zhangsna",12,"nan","默默大學(xué)","機(jī)械專業(yè)");
Teacher t = new Teacher("lili",30,"nv","默默大學(xué)","教授","機(jī)械");
s.showInfo();
t.showInfo();
}
}
class People{
String name;
int age;
String sex;
public People(String name, int age, String sex) {
super();
this.name = name;
this.age = age;
this.sex = sex;
}
}

interface JieKou{
final String COUNTRY="china";
public void showInfo();

}

class Student extends People implements JieKou{
private String school;
private String zhuanye;
@Override
public void showInfo() {
System.out.println("姓名:"+name+"\t年齡:"+age+"性別:"+sex+"學(xué)校:"+school+",專業(yè):"+zhuanye);

}
public Student(String name, int age, String sex, String school, String zhuanye) {
super(name, age, sex);
this.school = school;
this.zhuanye = zhuanye;
}

}
class Teacher extends People implements JieKou{
private String school;
private String zhicheng;
private String teach;
@Override
public void showInfo() {
System.out.println("姓名:"+name+"\t年齡:"+age+"性別:"+sex+"學(xué)校:"+school+",職稱:"+zhicheng+",主講課程:"+teach);

}
public Teacher(String name, int age, String sex, String school, String zhicheng, String teach) {
super(name, age, sex);
this.school = school;
this.zhicheng = zhicheng;
this.teach = teach;
}

}
就這些

請(qǐng)問大家一道JAVA編程題目求大神幫助

創(chuàng)建一個(gè)類Point,包含兩個(gè)成員變量x、y分別表示x和y坐標(biāo),兩個(gè)構(gòu)造器Point()和Point(x0,y0),以及一個(gè)movePoint(int dx,int dy)方法來實(shí)現(xiàn)點(diǎn)的位置移動(dòng)。編寫一個(gè)可運(yùn)行類PointDemo,在main方法中創(chuàng)建兩個(gè)Point類的對(duì)象p1和P2,要求分別用不同的構(gòu)造方法創(chuàng)建。在p1和P2對(duì)象中分別調(diào)用movePoint方法后,打印x和y的值。
class Point { int x,y; public Point() { x=0; y=0; } public Point(int x,int y) { this.x=x; this.y=y; } public void movePoint(int dx,int dy) { x+=dx; y+=dy; } } public class PointDemo { public static void main(String[] args) { Point p1=new Point(); Point P2=new Point(8,9); p1.movePoint(4, 5); System.out.println("對(duì)象p1中的x,y移動(dòng)后的值分別為:x="+p1.x+"\t"+"y="+p1.y); P2.movePoint(5, 6); System.out.println("對(duì)象P2中的x,y移動(dòng)后的值分別為:x="+P2.x+"\t"+"y="+P2.y); } } 呵呵,大概就是上面的了

相關(guān)推薦:

網(wǎng)頁版權(quán)信息(網(wǎng)頁版權(quán)怎么寫)

注冊(cè)商標(biāo)查詢(注冊(cè)商標(biāo)該怎么查詢)

商標(biāo)使用許可(商標(biāo)使用許可的種類有哪些)

表演者享有哪些權(quán)利(表演者對(duì)其表演依法享有什么權(quán)利呢)

商標(biāo)的侵權(quán)處罰(商標(biāo)侵權(quán)解決辦法)

熱門標(biāo)簽