1. Write a Java application that consists of 2 classes: The Print class and the main class E. Print
There is a method in the class output () function that outputs 100 ~ 999 of all daffodils (the number of
The cubic and equals this three-digit number itself, such as: 371 = 33 + 73 + 13. ) in main class E, in the Main method
Test the class print.
|
Package liu0917;
public class Print
{
void Output ()
{
for (int i =100;i<=999;i++)
{
if (Math.pow (i/100,3) +math.pow (i%10,3) +math.pow (i/10%10, 3) ==i)
{
System.out.println (i);
}
}
}
}
|
|
1
2
3
4
5
6
7
8
9
10
11 |
Package liu0917;
public class E {
public static void Main (string[] args)
{
Print pr=new print ();
Pr.output ();
}
} |
2. Write Java applications. First, define a print class that has a method void output (int
x), if the value of X is 1, the uppercase English alphabet is printed in the console, and if the value of X is 2,
The console prints a lowercase English alphabet. Second, define a main class--testclass, in the main class
The main method creates an object of the print class, using this object to call the method output () to print a large
Lower case English alphabet.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21st
22
23
24
25
26
27
28
29
30
31
32 |
Package liu0917;
public class Print2
{
int x;
void Output ()
{
if (x==1)
{
for (int i =65;i<=90;i++)//position of uppercase letters in char type
{
char a = (char) i;
System.out.print (a);
}
}
else if (x==2)
{
for (int i =97;i<=122;i++)
{
char a = (char) i;
System.out.print (a);
}
}
Else
{
SYSTEM.OUT.PRINTLN ("incorrect input");
}
}
}
|
|
1
2
3
4
5 P align= ' left ' >6
7
8
9
10
11
12
13
14
15
16
17
18 |
package liu0917;
&NBSP;
import java.util.scanner;
&NBSP;
public class testclass2 {
public static void main (string[] args)
{
print2 PR = new print2 ();
scanner SC = new scanner (System.in);
system.out.println ("Please enter the value of X");
pr.x=sc.nextint ();
pr.output ();
&NBSP;
&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP;}
&NBSP;
|
3.
. Write Java applications as required.
(1) Create a class called Cat:
Properties: Name, fur color, age
Behavior: Display name, shout
(2) write the main class:
Create an object cat, named "Nicole", Hair color is "gray", age 2 years old, lost on the screen
Out of the object's fur color and age, let the object call display names and shout two methods.
Package Com.hanqi;public class Mao {String name,maose;int age;void Xingwei () {System.out.println ("Cat's Name:" +name); System.out.println ("Cat's Cry:" + "meow Meow");}}
Package Com.hanqi;import Java.util.scanner;public class Test02 {public static void main (string[] args) {Mao ma=new Mao (); m A.name= "Nicole"; ma.maose= "Gray"; ma.age=2; Scanner sc=new Scanner (system.in); SYSTEM.OUT.PRINTLN ("Input cat Color:"); String Str=sc.nextline (); SYSTEM.OUT.PRINTLN ("Input cat Age:"); int in=sc.nextint (); if (Ma.maose.equals (str)) {Ma.xingwei ();} ELSE{SYSTEM.OUT.PRINTLN ("Cannot query cat Information");}}}
java-object-oriented basic exercises