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

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

首頁 > 知識產權2021-12-04 11:54:07

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

(模式識別方面,四個連續相等的數)編寫下面的方法,測試某個數組中是否有四個連續的值相同的數字rn publicBoolean isConsecutiveFour(int[] values)rn編寫測試程序,提示用戶輸入一個整數數列,如果這個數列有四個連續的具有相同值的數,那就顯示true,否則顯示false。
代碼如下……
參數跟返回值你可以自己添加咯!
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++) {
//防止數組越界操作
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");
}
-------------------------------------分割完結線--------------------------
public static void main(String[] args) {
isConsecutiveFour(new int[]{5,2,3,5});//用戶輸入的數
}

public static Boolean isConsecutiveFour(int[] values){

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

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循環

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),并且這兩個類都是類Shape的子類。類Shape聲明如下:rnrnpublic class Shape {rnprivate String name;rnrnpublic Shape(){rn}rnpublic Shape(String name){rnthis.name = name;rn}rn}
就是叫你定義2個類 一個為基本圖形線段(Line) ,一個為矩形(Rectangle)。這2個類都要繼承Shape類
public class Line extends Shape{
public Line (String name){
super(name);
}
}

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

求一道Java編程題!!!

求一道Java編程題!!!編寫一個抽象類Person,內有變量姓名name,年齡age,性別sex,有構造方法。定義一個接口Jiekou,接口中有常量國籍country和顯示成員變量的printinfo()方法。定義Person類的子類Student,增加變量學校school、專業zhuanye;定義Person類的子類Teacher,增加變量學校school、職稱zhicheng、主講課程teach。類Student和Teacher都使用了該接口。寫出一個主類,測試上述類的正確性,測試時使用上轉型對象和接口回調技術來體現多態性
--接口
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());

}

}
--測試類
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 {// 測試類
public static void main(String[] args) throws IOException {

Student s = new Student("zhangsna",12,"nan","默默大學","機械專業");
Teacher t = new Teacher("lili",30,"nv","默默大學","教授","機械");
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+"學校:"+school+",專業:"+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+"學校:"+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;
}

}
就這些

請問大家一道JAVA編程題目求大神幫助

創建一個類Point,包含兩個成員變量x、y分別表示x和y坐標,兩個構造器Point()和Point(x0,y0),以及一個movePoint(int dx,int dy)方法來實現點的位置移動。編寫一個可運行類PointDemo,在main方法中創建兩個Point類的對象p1和P2,要求分別用不同的構造方法創建。在p1和P2對象中分別調用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("對象p1中的x,y移動后的值分別為:x="+p1.x+"\t"+"y="+p1.y); P2.movePoint(5, 6); System.out.println("對象P2中的x,y移動后的值分別為:x="+P2.x+"\t"+"y="+P2.y); } } 呵呵,大概就是上面的了

相關推薦:

侵犯版權的行為有哪些(18種侵權行為)

申請專利的步驟是怎樣的(專利申請的一般步驟是什么)

哪些是假冒專利的行為(哪些行為構成假冒專利)

如何辦理商標異議和答辯(商標異議答辯流程)

什么是專利權轉讓合同(專利權轉讓合同是怎樣的)