
正文
java坑爹代码题目 javaoop代码题
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
求问一道java异常的题目 ,代码写了一部分了,但结果跟要求不同
x=Double.parseDouble(arg[0]);
y=Double.parseDouble(arg[1]);
这两句放到if判断的后面,因为你先处理这两句条件不符的时候直接抛出下标越界结束程序了
相关问答
Q1: 求教,JAVA这题好难
第一题代码如下,请参照:
public class TestHelloWorld {
public static void main(String[] args) {
String s="HelloWorld";
char[] c=s.toCharArray();
StringBuffer sb=new StringBuffer();
for (int i = c.length-1; i = 0; i--) {
char chr=c[i];
if(Character.isUpperCase(chr)){
chr=Character.toLowerCase(chr);
}else {
chr=Character.toUpperCase(chr);
}
sb.append(chr);
}
System.out.println(sb.toString());
}
}
运行结果如下:
第二题代码如下:
import java.util.Random;
public class TestRandom {
public static void main(String[] args) {
Random rand = new Random();
int[] num = new int[5];
for (int i = 0; i num.length; i++) {
num[i] = 20 + rand.nextInt(31);
System.out.println(num[i]);
}
}
}
Q2: 一道Java题目,如下,为什么我的代码错误了?
import java.util.Arrays;
import java.util.Scanner;
public class ff {
public static void main(String[] args) {
Scanner cin = new Scanner(System. in );
int n, i = 2;
n = cin.nextInt();
cin.close();
if (n == 1) {
System.out.print(1);
} else if (n = 2 n 40) {
int[] b = new int[n];
b[0] = 1;
b[1] = 1;
while (i = 2 i n) {
b[i] = b[i - 1] + b[i - 2];
i++;
}
for (i = 0; i b.length - 1; i++) {
System.out.print(b[i] + " ");
}
System.out.print(b[b.length - 1]);
} else {
System.out.println("一个整数N(N不能大于40)java坑爹代码题目,N=1 且 N40");
}
}
}
Q3: 一道对于我很难的 java题目 求救~
1.
TestRodent.java
class Rodent {
public void run(){
System.out.println("Rodent run!");
}
}
class Mouse extends Rodent{
public void run(){
System.out.println("Mouse run!");
}
}
class Gerbil extends Rodent{
public void run(){
System.out.println("Gerbil run!");
}
}
class Hamster extends Rodent{
public void run(){
System.out.println("Hamster run!");
}
}
public class TestRodent{
public static void main(String args[]){
Rodent[] r=new Rodent[]{new Mouse(),new Gerbil(),new Hamster()};
r[0].run();
r[1].run();
r[2].run();
}
}
2.AbstractTest.java
abstract class Rodent {
public void run(){
System.out.println("Rodent run!");
}
}
class Mouse extends Rodent{
public void run(){
System.out.println("Mouse run!");
}
}
class Gerbil extends Rodent{
public void run(){
System.out.println("Gerbil run!");
}
}
class Hamster extends Rodent{
public void run(){
System.out.println("Hamster run!");
}
}
public class AbstractTest {
public static void main(String args[]){
Rodent[] r=new Rodent[]{new Mouse(),new Gerbil(),new Hamster()};
r[0].run();
r[1].run();
r[2].run();
}
}
3.
InterRodent.java
interface Rodent {
public void run();
}
class Mouse implements Rodent{
public void run(){
System.out.println("Mouse run!");
}
}
class Gerbil implements Rodent{
public void run(){
System.out.println("Gerbil run!");
}
}
class Hamster implements Rodent{
public void run(){
System.out.println("Hamster run!");
}
}
public class InterRodent {
public static void main(String args[]){
Rodent[] r=new Rodent[]{new Mouse(),new Gerbil(),new Hamster()};
r[0].run();
r[1].run();
r[2].run();
}
}
已经给楼主写好了..
祝楼主早日成功!!!
以后可不能养成这样的习惯让别人来
帮你做...这样你怎么能学到东西呢??
呵呵.....
Q4: 一道java题目,求大神解答,我的代码哪里错了
for(int i=6;i=30;i++){
int s=i*12;
这一句中s要定义在for循环外
Q5: 今天老师出的个狠无聊的一个JAVA编程问题.希望各位能帮忙解决下!
呵呵java坑爹代码题目,确实无聊java坑爹代码题目,不过学习还是必须java坑爹代码题目的。代码如下java坑爹代码题目:
public class TestDays {
public static void main(String[] args) {
int y, m; //定义变量,分别用来接收年月
int total = 0; //储存输入月份后有多少天
Scanner sc = new Scanner(System.in);
System.out.print("请输入年份:");
y = sc.nextInt();
System.out.print("请输入月份:");
m = sc.nextInt();
if(y =1900 y=9999)
{
if(m =1 m=12)
{
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
total = 31;
break;
case 4:
case 6:
case 9:
case 11:
total = 30;
break;
case 2:
if ((y % 100 != 0) (y % 4 == 0) || (y % 400 == 0))
{
total = 29;
}
else
{
total = 28;
}
break;
}
System.out.print(y + "年" + m + "月有" + total + "天");
}
else
{
System.out.print("月份输入有误!");
}
}
else
{
System.out.print("年份输入有误!");
}
}
}
关于java坑爹代码题目和javaoop代码题的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。





